Package edu.umd.cs.findbugs

Examples of edu.umd.cs.findbugs.BugInstance


    @Override
    public void visit(LocalVariable obj) {
        if (isReservedName(obj.getName())) {
            LocalVariableAnnotation var = new LocalVariableAnnotation(obj.getName(), obj.getIndex(), obj.getStartPC());
            SourceLineAnnotation source = SourceLineAnnotation.fromVisitedInstruction(getClassContext(), this, obj.getStartPC());
            BugInstance bug = new BugInstance(this, "NM_FUTURE_KEYWORD_USED_AS_IDENTIFIER", NORMAL_PRIORITY)
            .addClassAndMethod(this).add(var).add(source);
            bugReporter.reportBug(bug);
        }
    }
View Full Code Here


                        } else if (getPrevOpcode(1) == I2L && getPrevOpcode(2) == IMUL && getPrevOpcode(4) == SIPUSH
                                && lastConstantForSIPUSH == 1000) {
                            priority = HIGH_PRIORITY;
                        }
                        BugInstance bug = new BugInstance(this, "ICAST_INT_2_LONG_AS_INSTANT", priority).addClassAndMethod(this)
                                .addCalledMethod(this).addValueSource(item, this).addSourceLine(this);
                        bugReporter.reportBug(bug);
                    }

                }
View Full Code Here

                || "Lcom/google/common/base/Optional;".equals(returnSignature);
    }

    @Override
    protected void accumulateBug() {
        bugAccumulator.accumulateBug(new BugInstance(this, "NP_OPTIONAL_RETURN_NULL",
                HIGH_PRIORITY).addClassAndMethod(this), this);
    }
View Full Code Here

            if (getMethodName().equals("<clinit>") && (getClassName().equals(clsName))) {
                return;
            }

            if (isStaticOnlyClass(xClass)) {
                bugReporter.reportBug(new BugInstance(this, "ISC_INSTANTIATE_STATIC_CLASS", LOW_PRIORITY).addClassAndMethod(
                        this).addSourceLine(this));
            }
        }

    }
View Full Code Here

                            || "java/io/PrintStream".equals(cl) && "printf".equals(nm) || cl.endsWith("Writer")
                            && "format".equals(nm) || cl.endsWith("Writer") && "printf".equals(nm)) || cl.endsWith("Logger")
                            && nm.endsWith("fmt")) {

                if (formatString.indexOf('\n') >= 0) {
                    bugReporter.reportBug(new BugInstance(this, "VA_FORMAT_STRING_USES_NEWLINE", NORMAL_PRIORITY)
                    .addClassAndMethod(this).addCalledMethod(this).addString(formatString)
                    .describe(StringAnnotation.FORMAT_STRING_ROLE).addSourceLine(this));
                }
                try {
                    String[] signatures = new String[arguments.length];
                    for (int i = 0; i < signatures.length; i++) {
                        signatures[i] = arguments[i].getSignature();
                    }
                    Formatter.check(formatString, signatures);

                } catch (IllegalFormatConversionException e) {

                    if (e.getConversion() == 'b') {
                        bugReporter.reportBug(new BugInstance(this, "VA_FORMAT_STRING_BAD_CONVERSION_TO_BOOLEAN", HIGH_PRIORITY)
                        .addClassAndMethod(this).addCalledMethod(this).addType(e.getArgumentSignature())
                        .describe(TypeAnnotation.FOUND_ROLE).addString(e.getFormatSpecifier())
                        .describe(StringAnnotation.FORMAT_SPECIFIER_ROLE).addString(formatString)
                        .describe(StringAnnotation.FORMAT_STRING_ROLE)
                        .addValueSource(arguments[e.getArgIndex()], getMethod(), getPC()).addSourceLine(this));
                    } else if (e.getArgumentSignature().charAt(0) == '[' && e.getConversion() == 's') {
                        bugReporter.reportBug(new BugInstance(this, "VA_FORMAT_STRING_BAD_CONVERSION_FROM_ARRAY", HIGH_PRIORITY)
                        .addClassAndMethod(this).addCalledMethod(this).addType(e.getArgumentSignature())
                        .describe(TypeAnnotation.FOUND_ROLE).addString(e.getFormatSpecifier())
                        .describe(StringAnnotation.FORMAT_SPECIFIER_ROLE).addString(formatString)
                        .describe(StringAnnotation.FORMAT_STRING_ROLE)
                        .addValueSource(arguments[e.getArgIndex()], getMethod(), getPC()).addSourceLine(this));
                    } else {
                        String aSig = e.getArgumentSignature();
                        char conversion = e.getConversion();
                        if ((conversion == 't' || conversion == 'T') && aSig.charAt(0) == 'L') {
                            ClassDescriptor argDescriptor = DescriptorFactory.createClassDescriptorFromFieldSignature(aSig);
                            assert argDescriptor != null : "sig started with L, should get descriptor";
                            String arg = argDescriptor.toDottedClassName();
                            try {
                                if (Hierarchy.isSubtype(arg,  java.util.Date.class.getName())
                                        || Hierarchy.isSubtype(arg,  java.util.Calendar.class.getName())) {
                                    return;
                                }
                            } catch (ClassNotFoundException e1) {
                                AnalysisContext.reportMissingClass(e1);
                            }

                        }
                        bugReporter.reportBug(new BugInstance(this, "VA_FORMAT_STRING_BAD_CONVERSION", HIGH_PRIORITY)
                        .addClassAndMethod(this).addCalledMethod(this).addType(aSig)
                        .describe(TypeAnnotation.FOUND_ROLE).addString(e.getFormatSpecifier())
                        .describe(StringAnnotation.FORMAT_SPECIFIER_ROLE).addString(formatString)
                        .describe(StringAnnotation.FORMAT_STRING_ROLE)
                        .addValueSource(arguments[e.getArgIndex()], getMethod(), getPC()).addSourceLine(this));
                    }
                } catch (IllegalArgumentException e) {
                    bugReporter.reportBug(new BugInstance(this, "VA_FORMAT_STRING_ILLEGAL", HIGH_PRIORITY)
                    .addClassAndMethod(this).addCalledMethod(this).addString(formatString)
                    .describe(StringAnnotation.FORMAT_STRING_ROLE).addSourceLine(this));
                } catch (MissingFormatArgumentException e) {

                    if (e.pos < 0) {
                        bugReporter.reportBug(new BugInstance(this, "VA_FORMAT_STRING_NO_PREVIOUS_ARGUMENT", HIGH_PRIORITY)
                        .addClassAndMethod(this).addCalledMethod(this).addString(e.formatSpecifier)
                        .describe(StringAnnotation.FORMAT_SPECIFIER_ROLE).addString(formatString)
                        .describe(StringAnnotation.FORMAT_STRING_ROLE).addSourceLine(this));
                    } else {
                        bugReporter.reportBug(new BugInstance(this, "VA_FORMAT_STRING_MISSING_ARGUMENT", HIGH_PRIORITY)
                        .addClassAndMethod(this).addCalledMethod(this).addString(e.formatSpecifier)
                        .describe(StringAnnotation.FORMAT_SPECIFIER_ROLE).addString(formatString)
                        .describe(StringAnnotation.FORMAT_STRING_ROLE).addInt(e.pos + 1)
                        .describe(IntAnnotation.INT_EXPECTED_ARGUMENTS).addInt(arguments.length)
                        .describe(IntAnnotation.INT_ACTUAL_ARGUMENTS).addSourceLine(this));
                    }

                } catch (ExtraFormatArgumentsException e) {
                    int priority = NORMAL_PRIORITY;
                    String pattern = "VA_FORMAT_STRING_EXTRA_ARGUMENTS_PASSED";
                    if (e.used == 0) {
                        priority = HIGH_PRIORITY;
                        if (formatString.indexOf("{0") >= 0 || formatString.indexOf("{1") >= 0) {
                            pattern = "VA_FORMAT_STRING_EXPECTED_MESSAGE_FORMAT_SUPPLIED";
                        }
                    }

                    bugReporter.reportBug(new BugInstance(this, pattern, priority).addClassAndMethod(this).addCalledMethod(this)
                            .addString(formatString).describe(StringAnnotation.FORMAT_STRING_ROLE).addInt(e.used)
                            .describe(IntAnnotation.INT_EXPECTED_ARGUMENTS).addInt(e.provided)
                            .describe(IntAnnotation.INT_ACTUAL_ARGUMENTS).addSourceLine(this));
                } catch (FormatterNumberFormatException e) {
                    bugReporter.reportBug(new BugInstance(this, "VA_FORMAT_STRING_ILLEGAL", NORMAL_PRIORITY)
                    .addClassAndMethod(this).addCalledMethod(this).addString(formatString)
                    .describe(StringAnnotation.FORMAT_STRING_ROLE)
                    .addString("Can't use " + e.getTxt() + " for " + e.getKind()).describe(StringAnnotation.STRING_MESSAGE)
                    .addSourceLine(this));
                }
View Full Code Here

            }
            hq.pushHash(getSigConstantOperand());

            priority = hq.getPriority();
            if (priority <= Priorities.LOW_PRIORITY) {
                accumulator.accumulateBug(new BugInstance(this, "NOISE_METHOD_CALL", priority).addClassAndMethod(this)
                        .addCalledMethod(this), this);
            }
            break;
        case GETFIELD:
        case PUTFIELD:
        case GETSTATIC:
        case PUTSTATIC:
            hq.pushHash(getClassConstantOperand());
            if (getNameConstantOperand().indexOf('$') == -1) {
                hq.pushHash(getNameConstantOperand());
            }
            hq.pushHash(getSigConstantOperand());
            priority = hq.getPriority();
            if (priority <= Priorities.LOW_PRIORITY) {
                accumulator.accumulateBug(new BugInstance(this, "NOISE_FIELD_REFERENCE", priority).addClassAndMethod(this)
                        .addReferencedField(this), this);
            }
            break;
        case CHECKCAST:
        case INSTANCEOF:
        case NEW:
            hq.pushHash(getClassConstantOperand());
            break;
        case IFEQ:
        case IFNE:
        case IFNONNULL:
        case IFNULL:
        case IF_ICMPEQ:
        case IF_ICMPNE:
        case IF_ICMPLE:
        case IF_ICMPGE:
        case IF_ICMPGT:
        case IF_ICMPLT:
        case IF_ACMPEQ:
        case IF_ACMPNE:
        case RETURN:
        case ARETURN:
        case IRETURN:
        case MONITORENTER:
        case MONITOREXIT:
        case IINC:
        case NEWARRAY:
        case TABLESWITCH:
        case LOOKUPSWITCH:
        case LCMP:
        case INEG:
        case IADD:
        case IMUL:
        case ISUB:
        case IDIV:
        case IREM:
        case IXOR:
        case ISHL:
        case ISHR:
        case IUSHR:
        case IAND:
        case IOR:
        case LAND:
        case LOR:
        case LADD:
        case LMUL:
        case LSUB:
        case LDIV:
        case LSHL:
        case LSHR:
        case LUSHR:
        case AALOAD:
        case AASTORE:
        case IALOAD:
        case IASTORE:
        case BALOAD:
        case BASTORE:
            hq.push(seen);
            priority = hq.getPriority();
            if (priority <= Priorities.LOW_PRIORITY) {
                accumulator.accumulateBug(
                        new BugInstance(this, "NOISE_OPERATION", priority).addClassAndMethod(this).addString(OPCODE_NAMES[seen]),
                        this);
            }
            break;
        default:
            break;
View Full Code Here

        if (DEBUG) {
            System.out.println("FFI: visiting " + getFullyQualifiedMethodName());
        }
        if (getMethodName().equals("finalize") && getMethodSig().equals("()V") && (obj.getAccessFlags() & (ACC_PUBLIC)) != 0) {
            bugReporter
            .reportBug(new BugInstance(this, "FI_PUBLIC_SHOULD_BE_PROTECTED", NORMAL_PRIORITY).addClassAndMethod(this));
        }
    }
View Full Code Here

        boolean superHasNoFinalizer = overridesFinalizeIn.equals("java.lang.Object");
        // System.out.println("superclass: " + superclassName);
        if (obj.getCode().length == 1) {
            if (superHasNoFinalizer) {
                if (!getMethod().isFinal()) {
                    bugReporter.reportBug(new BugInstance(this, "FI_EMPTY", NORMAL_PRIORITY).addClassAndMethod(this));
                }
            } else {
                bugReporter.reportBug(new BugInstance(this, "FI_NULLIFY_SUPER", NORMAL_PRIORITY).addClassAndMethod(this)
                        .addClass(overridesFinalizeIn));
            }
        } else if (obj.getCode().length == 5 && sawSuperFinalize) {
            bugReporter.reportBug(new BugInstance(this, "FI_USELESS", NORMAL_PRIORITY).addClassAndMethod(this));
        } else if (!sawSuperFinalize && !superHasNoFinalizer) {
            bugReporter.reportBug(new BugInstance(this, "FI_MISSING_SUPER_CALL", NORMAL_PRIORITY).addClassAndMethod(this)
                    .addClass(overridesFinalizeIn));
        }
    }
View Full Code Here

    @Override
    public void sawOpcode(int seen) {
        if (seen == INVOKEVIRTUAL && getNameConstantOperand().equals("finalize") && getSigConstantOperand().equals("()V")) {
            bugAccumulator.accumulateBug(
                    new BugInstance(this, "FI_EXPLICIT_INVOCATION", getMethodName().equals("finalize")
                            && getMethodSig().equals("()V") ? HIGH_PRIORITY : NORMAL_PRIORITY).addClassAndMethod(this)
                            .addCalledMethod(this), this);

        }
        if (seen == INVOKESPECIAL && getNameConstantOperand().equals("finalize")) {
View Full Code Here

        if (Hierarchy.isMonitorWait(location.getHandle().getInstruction(), cpg)) {
            int count = dataflow.getFactAtLocation(location).getNumLockedObjects();
            if (count > 1) {
                // A wait with multiple locks held?
                String sourceFile = javaClass.getSourceFileName();
                possibleWaitBugs.add(new BugInstance(this, "TLW_TWO_LOCK_WAIT", HIGH_PRIORITY).addClassAndMethod(methodGen,
                        sourceFile).addSourceLine(classContext, methodGen, sourceFile, location.getHandle()));
            }
        }
        if (Hierarchy.isMonitorNotify(location.getHandle().getInstruction(), cpg)) {
            int count = dataflow.getFactAtLocation(location).getNumLockedObjects();
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.