Package edu.umd.cs.findbugs

Examples of edu.umd.cs.findbugs.BugInstance


                        return;
                    }
                    priority++;
                }

                BugInstance bug = new BugInstance(this, "SA_FIELD_SELF_" + op, priority)
                .addClassAndMethod(this).addField(field0);

                if (this.isMethodCall()) {
                    bug.addCalledMethod(this);
                }
                bugAccumulator.accumulateBug(bug, this);
            }

            else if (opCode == IXOR && item0.equals(item1)) {
                LocalVariableAnnotation localVariableAnnotation = LocalVariableAnnotation.getLocalVariableAnnotation(this, item0);
                if (localVariableAnnotation != null) {
                    bugAccumulator.accumulateBug(
                            new BugInstance(this, "SA_LOCAL_SELF_" + op, linesDifference > 1 ? NORMAL_PRIORITY : HIGH_PRIORITY).addClassAndMethod(this).add(
                                    localVariableAnnotation), this);
                }
            }
        }
    }
View Full Code Here


                        // local variable
                        // number of the parameter, not the parameter number.
                        //
                        int paramLocal = xmethod.isStatic() ? p : p + 1;

                        reporter.reportBug(new BugInstance(this, "NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE",
                                NORMAL_PRIORITY).addClassAndMethod(jclass, method).add(
                                        LocalVariableAnnotation.getParameterLocalVariableAnnotation(method, paramLocal)));

                    }
View Full Code Here

                    priority++;
                }

                //                System.out.println("Found it");
                bugAccumulator.accumulateBug(
                        new BugInstance(this, "IA_AMBIGUOUS_INVOCATION_OF_INHERITED_OR_OUTER_METHOD", priority)
                        .addClassAndMethod(this).addMethod(invokedMethod).describe("METHOD_INHERITED")
                        .addMethod(alternativeMethod).describe("METHOD_ALTERNATIVE_TARGET"), this);
                break;
            }
        }
View Full Code Here

    }

    @Override
    public void visit(Field obj) {
        if (!obj.isFinal() && !obj.isTransient() && !obj.isVolatile()) {
            bugReporter.reportBug(new BugInstance(this, "JCIP_FIELD_ISNT_FINAL_IN_IMMUTABLE_CLASS", NORMAL_PRIORITY).addClass(
                    this).addVisitedField(this));
        }
    }
View Full Code Here

            OpcodeStack.Item left = stack.getStackItem(1);
            OpcodeStack.Item right = stack.getStackItem(0);
            if (badUseOfCompareResult(left, right)) {
                XMethod returnValueOf = left.getReturnValueOf();
                assert returnValueOf != null;
                bugAccumulator.accumulateBug(new BugInstance(this, "RV_CHECK_COMPARETO_FOR_SPECIFIC_RETURN_VALUE", NORMAL_PRIORITY)
                .addClassAndMethod(this).addMethod(returnValueOf).describe(MethodAnnotation.METHOD_CALLED).addValueSource(right, this), this);
            } else if (badUseOfCompareResult(right, left)) {
                XMethod returnValueOf = right.getReturnValueOf();
                assert returnValueOf != null;
                bugAccumulator.accumulateBug(new BugInstance(this, "RV_CHECK_COMPARETO_FOR_SPECIFIC_RETURN_VALUE", NORMAL_PRIORITY)
                .addClassAndMethod(this).addMethod(returnValueOf).describe(MethodAnnotation.METHOD_CALLED).addValueSource(left, this), this);
            }
            break;
        default:
            break;
        }

        checkForInitWithoutCopyOnStack: if (seen == INVOKESPECIAL && getNameConstantOperand().equals("<init>")) {
            int arguments = PreorderVisitor.getNumberArguments(getSigConstantOperand());
            OpcodeStack.Item invokedOn = stack.getStackItem(arguments);
            if (invokedOn.isNewlyAllocated() && (!getMethodName().equals("<init>") || invokedOn.getRegisterNumber() != 0)) {

                for (int i = arguments + 1; i < stack.getStackDepth(); i++) {
                    OpcodeStack.Item item = stack.getStackItem(i);
                    if (item.isNewlyAllocated() && item.getSignature().equals(invokedOn.getSignature())) {
                        break checkForInitWithoutCopyOnStack;
                    }
                }

                callSeen = XFactory.createReferencedXMethod(this);
                callPC = getPC();
                sawMethodCallWithIgnoredReturnValue();
                state = SCAN;
                previousOpcodeWasNEW = false;
                return;

            }
        }

        if (state == SAW_INVOKE && isPop(seen)) {
            sawMethodCallWithIgnoredReturnValue();
        } else if (INVOKE_OPCODE_SET.get(seen)) {
            callPC = getPC();
            callSeen = XFactory.createReferencedXMethod(this);
            state = SAW_INVOKE;
            if (DEBUG) {
                System.out.println("  invoking " + callSeen);
            }
        } else {
            state = SCAN;
        }

        if (seen == NEW) {
            previousOpcodeWasNEW = true;
        } else {
            if (seen == INVOKESPECIAL && previousOpcodeWasNEW) {
                CheckReturnValueAnnotation annotation = checkReturnAnnotationDatabase.getResolvedAnnotation(callSeen, false);
                if (annotation != null && annotation != CheckReturnValueAnnotation.CHECK_RETURN_VALUE_IGNORE) {
                    int priority = annotation.getPriority();
                    if (!checkReturnAnnotationDatabase.annotationIsDirect(callSeen)
                            && !callSeen.getSignature().endsWith(callSeen.getClassName().replace('.', '/') + ";")) {
                        priority++;
                    }
                    bugAccumulator.accumulateBug(new BugInstance(this, annotation.getPattern(), priority).addClassAndMethod(this)
                            .addCalledMethod(this), this);
                }

            }
            previousOpcodeWasNEW = false;
View Full Code Here

                String pattern = annotation.getPattern();
                if (callSeen.getName().equals("<init>")
                        && (callSeen.getClassName().endsWith("Exception") || callSeen.getClassName().endsWith("Error"))) {
                    pattern = "RV_EXCEPTION_NOT_THROWN";
                }
                BugInstance warning = new BugInstance(this, pattern, priority).addClassAndMethod(this).addMethod(callSeen)
                        .describe(MethodAnnotation.METHOD_CALLED);
                bugAccumulator.accumulateBug(warning, SourceLineAnnotation.fromVisitedInstruction(this, callPC));
            }
            state = SCAN;
        }
View Full Code Here

                    AnalysisContext.logError("error", e);
                } catch (CFGBuilderException e) {
                    AnalysisContext.logError("error", e);
                }

                BugInstance warning = new BugInstance(this, "NP_STORE_INTO_NONNULL_FIELD", tos.isDefinitelyNull() ? HIGH_PRIORITY
                        : NORMAL_PRIORITY).addClassAndMethod(classContext.getJavaClass(), method).addField(field)
                        .addOptionalAnnotation(variableAnnotation).addSourceLine(classContext, method, location);

                bugReporter.reportBug(warning);
            }
View Full Code Here

                priority = NORMAL_PRIORITY;
            } else if (methodName.equals("toString")) {
                bugPattern = "NP_TOSTRING_COULD_RETURN_NULL";
                priority = NORMAL_PRIORITY;
            }
            BugInstance warning = new BugInstance(this, bugPattern, priority).addClassAndMethod(classContext.getJavaClass(),
                    method).addOptionalAnnotation(variable);
            bugAccumulator.accumulateBug(warning, SourceLineAnnotation.fromVisitedInstruction(classContext, method, location));
        }
    }
View Full Code Here

        XMethod calledFrom = XFactory.createXMethod(classContext.getJavaClass(), method);

        if (safeCallToPrimateParseMethod(calledMethod, location)) {
            return;
        }
        BugInstance warning = new BugInstance(this, bugType, priority).addClassAndMethod(classContext.getJavaClass(), method)
                .addMethod(calledMethod).describe(MethodAnnotation.METHOD_CALLED).addSourceLine(classContext, method, location);

        //        boolean uncallable = false;
        if (!AnalysisContext.currentXFactory().isCalledDirectlyOrIndirectly(calledFrom) && calledFrom.isPrivate()) {

            propertySet.addProperty(GeneralWarningProperty.IN_UNCALLABLE_METHOD);
            //            uncallable = true;
        }
        // Check which params might be null
        addParamAnnotations(location, definitelyNullArgSet, unconditionallyDereferencedNullArgSet, propertySet, warning);

        if (bugType.equals("NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS")) {
            // Add annotations for dangerous method call targets
            for (JavaClassAndMethod dangerousCallTarget : veryDangerousCallTargetList) {
                warning.addMethod(dangerousCallTarget).describe(MethodAnnotation.METHOD_DANGEROUS_TARGET_ACTUAL_GUARANTEED_NULL);
            }
            dangerousCallTargetList.removeAll(veryDangerousCallTargetList);
            if (DEBUG_NULLARG) {
                // Add annotations for dangerous method call targets
                for (JavaClassAndMethod dangerousCallTarget : dangerousCallTargetList) {
                    warning.addMethod(dangerousCallTarget).describe(MethodAnnotation.METHOD_DANGEROUS_TARGET);
                }

                // Add safe method call targets.
                // This is useful to see which other call targets the analysis
                // considered.
                for (JavaClassAndMethod safeMethod : safeCallTargetSet) {
                    warning.addMethod(safeMethod).describe(MethodAnnotation.METHOD_SAFE_TARGET);
                }
            }
        }

        decorateWarning(location, propertySet, warning);
View Full Code Here

                boolean duplicated = isDuplicated(propertySet, location.getHandle().getPosition(), false);

                if (duplicated) {
                    return;
                }
                BugInstance warning = new BugInstance(this, "NP_NONNULL_PARAM_VIOLATION", priority)
                .addClassAndMethod(classContext.getJavaClass(), method).addMethod(m)
                .describe(MethodAnnotation.METHOD_CALLED).addParameterAnnotation(i, description)
                .addOptionalAnnotation(variableAnnotation).addSourceLine(classContext, method, location);

                propertySet.decorateBugInstance(warning);
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.BugInstance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.