Search in sources :

Example 1 with BugInstance

use of edu.umd.cs.findbugs.BugInstance in project guava-helper-for-java-8 by KengoTODA.

the class DependencyOnDeprecatedGuavaClassDetector method report.

private void report(@DottedClassName String referenced, @DottedClassName String replacement) {
    BugInstance bug = new BugInstance(this, "GUAVA_DEPEND_ON_DEPRECATED_CLASS", NORMAL_PRIORITY);
    bug.addString(referenced);
    bug.addString(replacement);
    if (this.visitingMethod()) {
        bug.addSourceLine(this);
        bug.addClassAndMethod(this);
    } else if (this.visitingField()) {
        bug.addField(this);
    }
    bugReporter.reportBug(bug);
}
Also used : BugInstance(edu.umd.cs.findbugs.BugInstance)

Example 2 with BugInstance

use of edu.umd.cs.findbugs.BugInstance in project wcomponents by BorderTech.

the class CheckWComponentFields method visitField.

/**
 * {@inheritDoc}
 */
@Override
public void visitField(final Field obj) {
    // All fields inside WComponents must be static or final
    if (!obj.isFinal() && !obj.isStatic()) {
        FieldAnnotation ann = FieldAnnotation.fromVisitedField(this);
        util.getBugReporter().reportBug(new BugInstance(this, "WCF_NON_FINAL_WCOMPONENT_FIELD", HIGH_PRIORITY).addClass(this).addField(ann));
    }
    // Component models must never be stored as fields
    if (util.isComponentModel(util.getClassNameFromSignature(obj.getType().getSignature()))) {
        FieldAnnotation ann = FieldAnnotation.fromVisitedField(this);
        util.getBugReporter().reportBug(new BugInstance(this, "WCF_COMPONENT_MODEL_FIELD", HIGH_PRIORITY).addClass(this).addField(ann));
    }
    // UIContexts must never be stored as fields
    if (util.isUIContext(util.getClassNameFromSignature(obj.getType().getSignature()))) {
        FieldAnnotation ann = FieldAnnotation.fromVisitedField(this);
        util.getBugReporter().reportBug(new BugInstance(this, "WCF_UICONTEXT_FIELD", HIGH_PRIORITY).addClass(this).addField(ann));
    }
}
Also used : FieldAnnotation(edu.umd.cs.findbugs.FieldAnnotation) BugInstance(edu.umd.cs.findbugs.BugInstance)

Example 3 with BugInstance

use of edu.umd.cs.findbugs.BugInstance in project wcomponents by BorderTech.

the class CheckGetComponentModel method sawOpcode.

/**
 * {@inheritDoc}
 */
@Override
public void sawOpcode(final int seen) {
    String methodName = getMethodName();
    boolean setter = methodName.startsWith("set");
    boolean getter = methodName.startsWith("get");
    String bug = null;
    int priority = NORMAL_PRIORITY;
    switch(seen) {
        case INVOKEVIRTUAL:
            {
                if (util.isWComponent(getClassConstantOperand())) {
                    // We don't check the specific return type as the code wouldn't have compiled if it's not a ComponentModel.
                    if (setter && "getComponentModel".equals(getNameConstantOperand()) && getSigConstantOperand().startsWith("()L")) {
                        // Suspicious to call getComponentModel in a setter,
                        // but will not necessarily lead to application errors.
                        bug = "WCGETM_INCORRECT_USE_OF_GETCOMPONENTMODEL";
                    } else if (getter && !"getOrCreateComponentModel".equals(methodName) && "getOrCreateComponentModel".equals(getNameConstantOperand()) && getSigConstantOperand().startsWith("()L")) {
                        // Suspicious to call getOrCreateComponentModel in a getter,
                        // but will not necessarily lead to application errors.
                        bug = "WCGETM_INCORRECT_USE_OF_GETORCREATECOMPONENTMODEL";
                    }
                } else if (util.isComponentModel(getClassConstantOperand()) && getNameConstantOperand().startsWith("set")) {
                    // TODO: this may not work if there are any double or long args.
                    Item model = stack.getStackItem(getNumberMethodArguments());
                    XMethod from = model.getReturnValueOf();
                    if (from != null && "getComponentModel".equals(from.getName()) && from.getSignature().startsWith("()L") && util.isWComponent(from.getClassName())) {
                        bug = "WCGETM_INCORRECT_USE_OF_GETCOMPONENTMODEL";
                        priority = HIGH_PRIORITY;
                    }
                }
                break;
            }
        case PUTFIELD:
            {
                if (util.isComponentModel(getClassConstantOperand())) {
                    Item model = stack.getStackItem(1);
                    XMethod from = model.getReturnValueOf();
                    if (from != null && "getComponentModel".equals(from.getName()) && from.getSignature().startsWith("()L") && util.isWComponent(from.getClassName())) {
                        bug = "WCGETM_INCORRECT_USE_OF_GETCOMPONENTMODEL";
                        priority = HIGH_PRIORITY;
                    }
                }
            }
    }
    if (bug != null) {
        util.getBugReporter().reportBug(new BugInstance(this, bug, priority).addClass(this).addMethod(MethodAnnotation.fromVisitedMethod(this)).addSourceLine(this, getPC()));
    }
}
Also used : Item(edu.umd.cs.findbugs.OpcodeStack.Item) XMethod(edu.umd.cs.findbugs.ba.XMethod) BugInstance(edu.umd.cs.findbugs.BugInstance)

Aggregations

BugInstance (edu.umd.cs.findbugs.BugInstance)3 FieldAnnotation (edu.umd.cs.findbugs.FieldAnnotation)1 Item (edu.umd.cs.findbugs.OpcodeStack.Item)1 XMethod (edu.umd.cs.findbugs.ba.XMethod)1