private void check(XClass xclass, ClassDescriptor annotation, boolean expectWarnings, int priority) { AnnotationValue expect = xclass.getAnnotation(annotation); if (expect == null) { return; } if (DEBUG) { System.out.println("*** Found " + annotation + " annotation on " + xclass); } ClassDescriptor descriptor = xclass.getClassDescriptor(); Collection<BugInstance> warnings = warningsByClass.get(descriptor); check(expect, descriptor, warnings, expectWarnings, priority, descriptor); }
/** * Add an XClass and all of its supertypes to the InheritanceGraph. * * @param xclass * an XClass * @return the ClassVertex representing the class in the InheritanceGraph */ private ClassVertex addClassAndGetClassVertex(XClass xclass) { if (xclass == null) { throw new IllegalStateException(); } LinkedList<XClass> workList = new LinkedList<>(); workList.add(xclass); while (!workList.isEmpty()) { XClass work = workList.removeFirst(); ClassVertex vertex = classDescriptorToVertexMap.get(work.getClassDescriptor()); if (vertex != null && vertex.isFinished()) { // This class has already been processed. continue; } if (vertex == null) { vertex = ClassVertex.createResolvedClassVertex(work.getClassDescriptor(), work); addVertexToGraph(work.getClassDescriptor(), vertex); } addSupertypeEdges(vertex, workList); vertex.setFinished(true); } return classDescriptorToVertexMap.get(xclass.getClassDescriptor()); }
private void scanForResourceTypes() { Subtypes2 subtypes2 = Global.getAnalysisCache().getDatabase(Subtypes2.class); Collection<XClass> knownClasses = subtypes2.getXClassCollection(); for (XClass xclass : knownClasses) { // Is this class a resource type? if (xclass.getAnnotation(cleanupObligation) != null) { // Add it as an obligation type database.getFactory().addObligation(xclass.getClassDescriptor().toDottedClassName()); } } if (DEBUG_ANNOTATIONS) { System.out.println("After scanning for resource types:"); for (Iterator<Obligation> i = database.getFactory().obligationIterator(); i.hasNext();) { Obligation obligation = i.next(); System.out.println(" " + obligation); } } } }
public static @CheckForNull XMethod findInvocationLeastUpperBound(XClass jClass, String methodName, String methodSig, boolean invokeStatic, boolean invokeInterface) { XMethod result = findMethod(jClass.getClassDescriptor(), methodName, methodSig, invokeStatic); if (result != null) { return result; } ClassDescriptor sClass = jClass.getSuperclassDescriptor(); if (sClass != null) { result = findInvocationLeastUpperBound(sClass, methodName, methodSig, invokeStatic, invokeInterface); if (result != null) { return result; } } for (ClassDescriptor i : jClass.getInterfaceDescriptorList()) { result = findInvocationLeastUpperBound(i, methodName, methodSig, invokeStatic, invokeInterface); if (result != null) { return result; } } return null; }
public static @CheckForNull XMethod findInvocationLeastUpperBound0(XClass jClass, String methodName, String methodSig, boolean invokeStatic, boolean invokeInterface) { XMethod result = findMethod(jClass.getClassDescriptor(), methodName, methodSig, invokeStatic); if (result != null) { return result; } if (invokeInterface) { for (ClassDescriptor i : jClass.getInterfaceDescriptorList()) { result = findInvocationLeastUpperBound(i, methodName, methodSig, invokeStatic, invokeInterface); if (result != null) { return result; } } } else { ClassDescriptor sClass = jClass.getSuperclassDescriptor(); if (sClass != null) { return findInvocationLeastUpperBound(sClass, methodName, methodSig, invokeStatic, invokeInterface); } } return null; }
private void compute() { if (defined == null) { // System.out.println("Computing"); defined = new HashSet<>(); Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); Collection<XClass> allClasses = subtypes2.getXClassCollection(); IAnalysisCache analysisCache = Global.getAnalysisCache(); for (XClass c : allClasses) { try { JavaClass jclass = analysisCache.getClassAnalysis(JavaClass.class, c.getClassDescriptor()); addAllDefinitions(jclass); } catch (MissingClassException e) { bugReporter.reportMissingClass(e.getClassDescriptor()); } catch (CheckedAnalysisException e) { bugReporter.logError("Could not find class " + c.getClassDescriptor().toDottedClassName(), e); } } // System.out.println("Done Computing: " + // defined.contains("edu.umd.cs.findbugs.ba.IsNullValueAnalysis.UNKNOWN_VALUES_ARE_NSP : Z")); } }
@Override public MethodVisitor visitMethod(int methodAccess, String methodName, String desc, String methodSignature, String[] exceptions) { if ((methodAccess & ACC_STATIC) != 0) { // skip static methods return null; } final XMethod xmethod = xclass.findMethod(methodName, desc, false); if (xmethod == null) { // unable to continue the analysis bugReporter.reportSkippedAnalysis(new MethodDescriptor(xclass.getClassDescriptor().getClassName(), methodName, desc, false)); return null; } return new DetectorNode(methodAccess, methodName, desc, methodSignature, exceptions, xmethod); }
.currentAnalysisContext() .getSubtypes2() .isSubtype(superXClass.getClassDescriptor(), DescriptorFactory.createClassDescriptor(java.io.Serializable.class)); superClassHasVoidConstructor = false;
if ((getPC() < lastQuestionableCheckTarget) && (lastQuestionableCheckTarget != -1)) { bugReporter.reportBug(new BugInstance(this, "AT_OPERATION_SEQUENCE_ON_CONCURRENT_ABSTRACTION", priority) .addClassAndMethod(this).addType(xClass.getClassDescriptor()).addCalledMethod(this) .addSourceLine(this));
String name = fieldClass.getClassDescriptor().getClassName(); if (name.startsWith("java/awt") || name.startsWith("javax/swing")) { return;
@Override public void visitClass(ClassDescriptor classDescriptor) throws CheckedAnalysisException { XClass xclass = Global.getAnalysisCache().getClassAnalysis(XClass.class, classDescriptor); // Is this class an obligation type? Obligation thisClassObligation = database.getFactory().getObligationByType(xclass.getClassDescriptor()); // Scan methods for uses of obligation-related annotations for (XMethod xmethod : xclass.getXMethods()) { // Is this method marked with @CreatesObligation? if (thisClassObligation != null) { if (xmethod.getAnnotation(createsObligation) != null) { database.addEntry(new MatchMethodEntry(xmethod, ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, thisClassObligation)); } // Is this method marked with @DischargesObligation? if (xmethod.getAnnotation(dischargesObligation) != null) { database.addEntry(new MatchMethodEntry(xmethod, ObligationPolicyDatabaseActionType.DEL, ObligationPolicyDatabaseEntryType.STRONG, thisClassObligation)); } } addObligations(xmethod); } }
} else { inheritedEqualsFromAbstractClass = we.isAbstract(); whereEqual = we.getClassDescriptor().getDottedClassName(); inheritedEquals = we.findMethod("equals", "(Ljava/lang/Object;)Z", false); if (inheritedEquals != null) { whereHashCode = "java.lang.Object"; } else { whereHashCode = wh.getClassDescriptor().getDottedClassName(); XMethod m = wh.findMethod("hashCode", "()I", false); if (m != null && m.isFinal()) {
private void check(XClass xclass, ClassDescriptor annotation, boolean expectWarnings, int priority) { AnnotationValue expect = xclass.getAnnotation(annotation); if (expect == null) { return; } if (DEBUG) { System.out.println("*** Found " + annotation + " annotation on " + xclass); } ClassDescriptor descriptor = xclass.getClassDescriptor(); Collection<BugInstance> warnings = warningsByClass.get(descriptor); check(expect, descriptor, warnings, expectWarnings, priority, descriptor); }
int numEnumValues(@CheckForNull XClass c) { if (c == null) { return -1; } int total = 0; String enumSignature = ClassName.toSignature(c.getClassDescriptor().getClassName()); for(XField f : c.getXFields()) { if (f.getSignature().equals(enumSignature) && f.isPublic() && f.isFinal()) { total++; } } return total; }
private void scanForResourceTypes() { Subtypes2 subtypes2 = Global.getAnalysisCache().getDatabase(Subtypes2.class); Collection<XClass> knownClasses = subtypes2.getXClassCollection(); for (XClass xclass : knownClasses) { // Is this class a resource type? if (xclass.getAnnotation(cleanupObligation) != null) { // Add it as an obligation type database.getFactory().addObligation(xclass.getClassDescriptor().toDottedClassName()); } } if (DEBUG_ANNOTATIONS) { System.out.println("After scanning for resource types:"); for (Iterator<Obligation> i = database.getFactory().obligationIterator(); i.hasNext();) { Obligation obligation = i.next(); System.out.println(" " + obligation); } } } }
public static @CheckForNull XMethod findInvocationLeastUpperBound(XClass jClass, String methodName, String methodSig, boolean invokeStatic, boolean invokeInterface) { XMethod result = findMethod(jClass.getClassDescriptor(), methodName, methodSig, invokeStatic); if (result != null) { return result; } ClassDescriptor sClass = jClass.getSuperclassDescriptor(); if (sClass != null) { result = findInvocationLeastUpperBound(sClass, methodName, methodSig, invokeStatic, invokeInterface); if (result != null) { return result; } } for (ClassDescriptor i : jClass.getInterfaceDescriptorList()) { result = findInvocationLeastUpperBound(i, methodName, methodSig, invokeStatic, invokeInterface); if (result != null) { return result; } } return null; }
public static @CheckForNull XMethod findInvocationLeastUpperBound0(XClass jClass, String methodName, String methodSig, boolean invokeStatic, boolean invokeInterface) { XMethod result = findMethod(jClass.getClassDescriptor(), methodName, methodSig, invokeStatic); if (result != null) { return result; } if (invokeInterface) { for (ClassDescriptor i : jClass.getInterfaceDescriptorList()) { result = findInvocationLeastUpperBound(i, methodName, methodSig, invokeStatic, invokeInterface); if (result != null) { return result; } } } else { ClassDescriptor sClass = jClass.getSuperclassDescriptor(); if (sClass != null) { return findInvocationLeastUpperBound(sClass, methodName, methodSig, invokeStatic, invokeInterface); } } return null; }
private void compute() { if (defined == null) { // System.out.println("Computing"); defined = new HashSet<String>(); Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); Collection<XClass> allClasses = subtypes2.getXClassCollection(); IAnalysisCache analysisCache = Global.getAnalysisCache(); for (XClass c : allClasses) { try { JavaClass jclass = analysisCache.getClassAnalysis(JavaClass.class, c.getClassDescriptor()); addAllDefinitions(jclass); } catch (MissingClassException e) { bugReporter.reportMissingClass(e.getClassDescriptor()); } catch (CheckedAnalysisException e) { bugReporter.logError("Could not find class " + c.getClassDescriptor().toDottedClassName(), e); } } // System.out.println("Done Computing: " + // defined.contains("edu.umd.cs.findbugs.ba.IsNullValueAnalysis.UNKNOWN_VALUES_ARE_NSP : Z")); } }
@Override public MethodVisitor visitMethod(int methodAccess, String methodName, String desc, String methodSignature, String[] exceptions) { if ((methodAccess & ACC_STATIC) != 0) { // skip static methods return null; } final XMethod xmethod = xclass.findMethod(methodName, desc, false); if (xmethod == null) { // unable to continue the analysis bugReporter.reportSkippedAnalysis(new MethodDescriptor(xclass.getClassDescriptor().getClassName(), methodName, desc, false)); return null; } return new DetectorNode(methodAccess, methodName, desc, methodSignature, exceptions, xmethod); }
@Override public void visitClass(ClassDescriptor classDescriptor) throws CheckedAnalysisException { XClass xclass = Global.getAnalysisCache().getClassAnalysis(XClass.class, classDescriptor); // Is this class an obligation type? Obligation thisClassObligation = database.getFactory().getObligationByType(xclass.getClassDescriptor()); // Scan methods for uses of obligation-related annotations for (XMethod xmethod : xclass.getXMethods()) { // Is this method marked with @CreatesObligation? if (thisClassObligation != null) { if (xmethod.getAnnotation(createsObligation) != null) { database.addEntry(new MatchMethodEntry(xmethod, ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, thisClassObligation)); } // Is this method marked with @DischargesObligation? if (xmethod.getAnnotation(dischargesObligation) != null) { database.addEntry(new MatchMethodEntry(xmethod, ObligationPolicyDatabaseActionType.DEL, ObligationPolicyDatabaseEntryType.STRONG, thisClassObligation)); } } addObligations(xmethod); } }