Package edu.umd.cs.findbugs

Examples of edu.umd.cs.findbugs.BugInstance


  @SuppressWarnings("HardcodedFileSeparator")
  @edu.umd.cs.findbugs.annotations.SuppressFBWarnings({"DB_DUPLICATE_SWITCH_CLAUSES"})
  @Nullable
  public static Icon getTinyIcon(final ExtendedProblemDescriptor problemDescriptor) {
    final BugInstance bugInstance = problemDescriptor.getBugInstance();
    final int priority = bugInstance.getPriority();
    final Icon icon;
    switch (priority) {
      case Detector.HIGH_PRIORITY :
        icon = ResourcesLoader.loadIcon("priority/bug_high_tiny.png");
        break;
View Full Code Here


  @SuppressWarnings("HardcodedFileSeparator")
  @edu.umd.cs.findbugs.annotations.SuppressFBWarnings({"DB_DUPLICATE_SWITCH_CLAUSES"})
  @Nullable
  public static Icon getCombinedIcon(final ExtendedProblemDescriptor problemDescriptor) {
    final BugInstance bugInstance = problemDescriptor.getBugInstance();
    final int priority = bugInstance.getPriority();
    final Icon icon;
    switch (priority) {
      case Detector.HIGH_PRIORITY :
        icon = ResourcesLoader.loadIcon("intentions/bugBulbHigh.png");
        break;
View Full Code Here

        while (dependencyGraph.size() > 0) {
            String clsName = dependencyGraph.keySet().iterator().next();
            Set<String> loop = lf.findLoop(dependencyGraph, clsName);
            boolean pruneLeaves;
            if (loop != null) {
                BugInstance bug = new BugInstance(this, "CD_CIRCULAR_DEPENDENCY", NORMAL_PRIORITY);
                for (String loopCls : loop) {
                    bug.addClass(loopCls);
                }
                bugReporter.reportBug(bug);
                pruneLeaves = removeLoopLinks(dependencyGraph, loop);
            } else {
                dependencyGraph.remove(clsName);
View Full Code Here

        // Report method pairs
        for (String propName : commonProperties) {
            MethodAnnotation getMethod = getMethods.get(propName);
            MethodAnnotation setMethod = setMethods.get(propName);

            bugReporter.reportBug(new BugInstance(this, "UG_SYNC_SET_UNSYNC_GET", NORMAL_PRIORITY).addClass(prevClassName)
                    .addMethod(getMethod).addMethod(setMethod));
        }
        getMethods.clear();
        setMethods.clear();
    }
View Full Code Here

                if (prevOpcode == LDC && stringConstant != null && stringConstant.length() > 0 && stringConstant.charAt(0) == '/') {
                    priority = LOW_PRIORITY;
                } else {
                    priority = adjustPriority(priority);
                }
                bugReporter.reportBug(new BugInstance(this, "UI_INHERITANCE_UNSAFE_GETRESOURCE", priority)
                .addClassAndMethod(this).addSourceLine(this));
                reportedForThisClass = true;

            } else if (state == 1 && !methodIsStatic && !classIsFinal && classIsVisibleToOtherPackages
                    && getNameConstantOperand().equals("getClass") && getSigConstantOperand().equals("()Ljava/lang/Class;")) {
View Full Code Here

        return "Ljava/lang/Boolean;".equals(returnSignature);
    }

    @Override
    protected void accumulateBug() {
        bugAccumulator.accumulateBug(new BugInstance(this, "NP_BOOLEAN_RETURN_NULL",
                getMethodName().startsWith("is") ? HIGH_PRIORITY : NORMAL_PRIORITY).addClassAndMethod(this), this);
    }
View Full Code Here

            for (XField f : needToInitialize) {
                if (initializedFields.contains(f)) {
                    continue;
                }

                BugInstance b = new BugInstance(this, "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", priority)
                .addClassAndMethod(this).addField(f);
                bugReporter.reportBug(b);
            }

        }
View Full Code Here

        case SAW_KEY_LOAD:
            if (((seen == INVOKEINTERFACE) || (seen == INVOKEVIRTUAL)) && ("get".equals(getNameConstantOperand()))
                    && ("(Ljava/lang/Object;)Ljava/lang/Object;".equals(getSigConstantOperand()))) {
                MethodAnnotation ma = MethodAnnotation.fromVisitedMethod(this);
                bugAccumulator.accumulateBug(new BugInstance(this, "WMI_WRONG_MAP_ITERATOR", NORMAL_PRIORITY).addClass(this)
                        .addMethod(ma), this);
                state = SAW_NOTHING;
            }
            break;
        default:
View Full Code Here

            }
        }
         */

        if (!hasEqualsObject && !hasEqualsSelf && hasEqualsOther) {
            BugInstance bug = new BugInstance(this, usesDefaultEquals ? "EQ_OTHER_USE_OBJECT" : "EQ_OTHER_NO_OBJECT",
                    NORMAL_PRIORITY).addClass(this).addMethod(equalsOtherMethod).addClass(equalsOtherClass);
            bugReporter.reportBug(bug);
        }
        if (!hasEqualsObject && hasEqualsSelf) {

            if (usesDefaultEquals) {
                int priority = HIGH_PRIORITY;
                if (usesDefaultHashCode || obj.isAbstract()) {
                    priority++;
                }
                if (!visibleOutsidePackage) {
                    priority++;
                }
                String bugPattern = "EQ_SELF_USE_OBJECT";

                BugInstance bug = new BugInstance(this, bugPattern, priority).addClass(getDottedClassName());
                if (equalsMethod != null) {
                    bug.addMethod(equalsMethod);
                }
                bugReporter.reportBug(bug);
            } else {
                int priority = NORMAL_PRIORITY;
                if (hasFields) {
                    priority--;
                }
                if (obj.isAbstract()) {
                    priority++;
                }
                String bugPattern = "EQ_SELF_NO_OBJECT";
                String superclassName = obj.getSuperclassName();
                if (superclassName.equals("java.lang.Enum")) {
                    bugPattern = "EQ_DONT_DEFINE_EQUALS_FOR_ENUM";
                    priority = HIGH_PRIORITY;
                }
                BugInstance bug = new BugInstance(this, bugPattern, priority).addClass(getDottedClassName());
                if (equalsMethod != null) {
                    bug.addMethod(equalsMethod);
                }
                bugReporter.reportBug(bug);
            }
        }

        // System.out.println("Class " + getDottedClassName());
        // System.out.println("usesDefaultEquals: " + usesDefaultEquals);
        // System.out.println("hasHashCode: : " + hasHashCode);
        // System.out.println("usesDefaultHashCode: " + usesDefaultHashCode);
        // System.out.println("hasEquals: : " + hasEqualsObject);
        // System.out.println("hasCompareToObject: : " + hasCompareToObject);
        // System.out.println("hasCompareToSelf: : " + hasCompareToSelf);

        if ((hasCompareToObject || hasCompareToSelf) && usesDefaultEquals) {
            BugInstance bug = new BugInstance(this, "EQ_COMPARETO_USE_OBJECT_EQUALS", obj.isAbstract() ? Priorities.LOW_PRIORITY
                    : Priorities.NORMAL_PRIORITY).addClass(this);
            if (compareToSelfMethod != null) {
                bug.addMethod(compareToSelfMethod);
            } else {
                bug.addMethod(compareToObjectMethod);
            }
            bugReporter.reportBug(bug);
        }
        if (!hasCompareToObject && !hasCompareToBridgeMethod && hasCompareToSelf) {
            if (!extendsObject) {
                bugReporter.reportBug(new BugInstance(this, "CO_SELF_NO_OBJECT", NORMAL_PRIORITY).addClass(getDottedClassName())
                        .addMethod(compareToMethod));
            }
        }

        // if (!hasFields) return;
        if (hasHashCode && !hashCodeIsAbstract && !(hasEqualsObject || hasEqualsSelf)) {
            int priority = LOW_PRIORITY;
            if (usesDefaultEquals) {
                bugReporter.reportBug(new BugInstance(this, "HE_HASHCODE_USE_OBJECT_EQUALS", priority).addClass(
                        getDottedClassName()).addMethod(hashCodeMethod));
            } else if (!inheritedEqualsIsFinal) {
                bugReporter.reportBug(new BugInstance(this, "HE_HASHCODE_NO_EQUALS", priority).addClass(getDottedClassName())
                        .addMethod(hashCodeMethod));
            }
        }
        if (equalsObjectIsAbstract) {
            // no errors reported
        } else if (!hasHashCode && (hasEqualsObject || hasEqualsSelf)) {
            EqualsKindSummary.KindOfEquals equalsKind = AnalysisContext.currentAnalysisContext().getEqualsKindSummary()
                    .get(new ClassAnnotation(obj.getClassName()));
            if (equalsKind == EqualsKindSummary.KindOfEquals.ALWAYS_FALSE) {
                return;
            }
            if (usesDefaultHashCode) {
                int priority = HIGH_PRIORITY;
                if (equalsMethodIsInstanceOfEquals) {
                    priority += 2;
                } else if (obj.isAbstract() || !hasEqualsObject) {
                    priority++;
                }
                if (priority == HIGH_PRIORITY) {
                    nonHashableClasses.add(getDottedClassName());
                }
                if (!visibleOutsidePackage) {
                    priority++;
                }
                BugInstance bug = new BugInstance(this, "HE_EQUALS_USE_HASHCODE", priority).addClass(getDottedClassName());
                if (equalsMethod != null) {
                    bug.addMethod(equalsMethod);
                }
                bugReporter.reportBug(bug);
            } else if (!inheritedHashCodeIsFinal && !whereHashCode.startsWith("java.util.Abstract")) {
                int priority = LOW_PRIORITY;

                if (hasEqualsObject && inheritedEqualsIsAbstract) {
                    priority++;
                }
                if (hasFields) {
                    priority--;
                }
                if (equalsMethodIsInstanceOfEquals || !hasEqualsObject) {
                    priority += 2;
                } else if (obj.isAbstract()) {
                    priority++;
                }
                BugInstance bug = new BugInstance(this, "HE_EQUALS_NO_HASHCODE", priority).addClass(getDottedClassName());
                if (equalsMethod != null) {
                    bug.addMethod(equalsMethod);
                }
                bugReporter.reportBug(bug);
            }
        }
        if (!hasHashCode && !hasEqualsObject && !hasEqualsSelf && !usesDefaultEquals && usesDefaultHashCode && !obj.isAbstract()
                && inheritedEqualsFromAbstractClass) {
            BugInstance bug = new BugInstance(this, "HE_INHERITS_EQUALS_USE_HASHCODE", NORMAL_PRIORITY)
            .addClass(getDottedClassName());
            if (equalsMethod != null) {
                bug.addMethod(equalsMethod);
            }
            bugReporter.reportBug(bug);
        }
        if (!hasEqualsObject && !hasEqualsSelf && !usesDefaultEquals && !obj.isAbstract() && hasFields && inheritedEquals != null
                && !inheritedEqualsIsFinal && !inheritedEqualsFromAbstractClass
                && !inheritedEquals.getClassDescriptor().getSimpleName().contains("Abstract")
                && !inheritedEquals.getClassDescriptor().getClassName().equals("java/lang/Enum")) {

            BugInstance bug = new BugInstance(this, "EQ_DOESNT_OVERRIDE_EQUALS", NORMAL_PRIORITY);

            // create annotation pointing to this class source line 1, otherwise the primary annotation shows parent class
            SourceLineAnnotation sourceLine = new SourceLineAnnotation(getDottedClassName(), obj.getSourceFileName(), 1, 1, 0, 0);
            bug.addClass(getDottedClassName()).add(sourceLine);
            bug.addMethod(inheritedEquals).describe(MethodAnnotation.METHOD_DID_YOU_MEAN_TO_OVERRIDE);
            bugReporter.reportBug(bug);
        }
    }
View Full Code Here

        }
        String name = obj.getName();
        String sig = obj.getSignature();
        if ((accessFlags & ACC_ABSTRACT) != 0) {
            if (name.equals("equals") && sig.equals("(L" + getClassName() + ";)Z")) {
                bugReporter.reportBug(new BugInstance(this, "EQ_ABSTRACT_SELF", LOW_PRIORITY).addClass(getDottedClassName()));
                return;
            } else if (name.equals("compareTo") && sig.equals("(L" + getClassName() + ";)I")) {
                bugReporter.reportBug(new BugInstance(this, "CO_ABSTRACT_SELF", LOW_PRIORITY).addClass(getDottedClassName()));
                return;
            }
        }
        boolean sigIsObject = sig.equals("(Ljava/lang/Object;)Z");
        if (name.equals("hashCode") && sig.equals("()I")) {
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.