/** * Get Collection of all XClass objects seen so far. * * @return Collection of all XClass objects seen so far */ public Collection<XClass> getXClassCollection() { return getSubtypes2().getXClassCollection(); }
public boolean isApplicationClass(ClassDescriptor desc) { return getSubtypes2().isApplicationClass(desc); }
/** * Return whether or not the given class is an application class. * * @param cls * the class to lookup * @return true if the class is an application class, false if not an * application class or if the class cannot be located */ public boolean isApplicationClass(JavaClass cls) { // return getSubtypes().isApplicationClass(cls); return getSubtypes2().isApplicationClass(DescriptorFactory.createClassDescriptor(cls)); }
static public boolean isCollection(ReferenceType target) throws ClassNotFoundException { Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); return subtypes2.isSubtype(target, COLLECTION_TYPE); } /** A collection, a map, or some other container */
/** A collection, a map, or some other container */ static public boolean isContainer(ReferenceType target) throws ClassNotFoundException { Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); return subtypes2.isSubtype(target, COLLECTION_TYPE) || subtypes2.isSubtype(target, MAP_TYPE); }
private boolean isThrowable(ReferenceType ref) /* * throws * ClassNotFoundException */{ try { Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); return subtypes2.isSubtype(ref, Type.THROWABLE); } catch (ClassNotFoundException e) { // We'll just assume that it's not an exception type. lookupFailureCallback.reportMissingClass(e); return false; } }
public void setAppClassList(List<ClassDescriptor> appClassCollection) { // FIXME: we really should drive the progress callback here HashSet<ClassDescriptor> appSet = new HashSet<>(appClassCollection); Collection<ClassDescriptor> allClassDescriptors = new ArrayList<>(DescriptorFactory.instance() .getAllClassDescriptors()); for (ClassDescriptor appClass : allClassDescriptors) { try { XClass xclass = currentXFactory().getXClass(appClass); if (xclass == null) { continue; } // Add the application class to the database if (appSet.contains(appClass)) { getSubtypes2().addApplicationClass(xclass); } else if (xclass instanceof ClassInfo) { getSubtypes2().addClass(xclass); } } catch (Exception e) { AnalysisContext.logError("Unable to get XClass for " + appClass, e); } } if (true && Subtypes2.DEBUG) { System.out.println(getSubtypes2().getGraph().getNumVertices() + " vertices in inheritance graph"); } }
@Override public void visit(JavaClass obj) { super.visit(obj); allowedFields = new HashSet<>(); fieldsModifyingMethods = new HashSet<>(); subtypes = null; if (!obj.isFinal() && !obj.isEnum()) { try { Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); subtypes = new HashSet<>(subtypes2.getSubtypes(getClassDescriptor())); subtypes.remove(getClassDescriptor()); } catch (ClassNotFoundException e) { } } }
/** * Return whether or not the given class is an application class. * * @param className * name of a class * @return true if the class is an application class, false if not an * application class or if the class cannot be located */ public boolean isApplicationClass(@DottedClassName String className) { // try { // JavaClass javaClass = lookupClass(className); // return isApplicationClass(javaClass); // } catch (ClassNotFoundException e) { // AnalysisContext.reportMissingClass(e); // return false; // } ClassDescriptor classDesc = DescriptorFactory.createClassDescriptorFromDottedClassName(className); return getSubtypes2().isApplicationClass(classDesc); }
private boolean extendsConcurrentMap(@DottedClassName String className) { if ("java.util.concurrent.ConcurrentHashMap".equals(className) || className.equals(concurrentMapDescriptor.getDottedClassName())) { return true; } ClassDescriptor c = DescriptorFactory.createClassDescriptorFromDottedClassName(className); Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); try { if (subtypes2.isSubtype(c, concurrentMapDescriptor)) { return true; } } catch (ClassNotFoundException e) { AnalysisContext.reportMissingClass(e); } return false; }
public static boolean isServletField(XField field) { ClassDescriptor classDescriptor = field.getClassDescriptor(); try { Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); if (subtypes2.isSubtype(classDescriptor, servlet) && !subtypes2.isSubtype(classDescriptor, singleThreadedServlet)) { return true; } } catch (ClassNotFoundException e) { assert true; } if (classDescriptor.getClassName().endsWith("Servlet")) { return true; } return false; }
public static boolean likelyTestCase(XMethod m) { if (m.getAnnotation(JUNIT4TEST) != null) { return true; } ClassDescriptor c = m.getClassDescriptor(); if (m.getName().startsWith("test") || m.getName().startsWith("assert")) { Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); try { if (subtypes2.isSubtype(c, JUNIT3TESTCASE)) { return true; } } catch (ClassNotFoundException e) { AnalysisContext.reportMissingClass(e); } } return false; }
@Override public void visitClassContext(ClassContext classContext) { Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); try { if (subtypes2.isSubtype(classContext.getClassDescriptor(), iteratorDescriptor)) { super.visitClassContext(classContext); } } catch (ClassNotFoundException e) { bugReporter.reportMissingClass(e); } }
public static boolean instanceOf(ClassDescriptor subDescriptor, @DottedClassName String dottedSupertype) { Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); ClassDescriptor superDescriptor = DescriptorFactory.createClassDescriptorFromDottedClassName(dottedSupertype); try { return subtypes2.isSubtype(subDescriptor, superDescriptor); } catch (ClassNotFoundException e) { AnalysisContext.reportMissingClass(e); return false; } }
public static boolean instanceOf(JavaClass subtype, @DottedClassName String dottedSupertype) { if (subtype.getClassName().equals(dottedSupertype) || subtype.getSuperclassName().equals(dottedSupertype)) { return true; } if ("java.lang.Object".equals(subtype.getSuperclassName()) && subtype.getInterfaceIndices().length == 0) { return false; } Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); ClassDescriptor subDescriptor = DescriptorFactory.createClassDescriptor(subtype); ClassDescriptor superDescriptor = DescriptorFactory.createClassDescriptorFromDottedClassName(dottedSupertype); try { return subtypes2.isSubtype(subDescriptor, superDescriptor); } catch (ClassNotFoundException e) { AnalysisContext.reportMissingClass(e); return false; } }
@Override public void report() { Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); for (XField f : AnalysisContext.currentXFactory().allFields()) { if (isVolatileArray(f) && subtypes2.isApplicationClass(f.getClassDescriptor())) { int priority = LOW_PRIORITY; if (initializationWrites.contains(f) && !otherWrites.contains(f)) { priority = NORMAL_PRIORITY; } bugReporter.reportBug(new BugInstance(this, "VO_VOLATILE_REFERENCE_TO_ARRAY", priority).addClass( f.getClassDescriptor()).addField(f)); } } }
public static boolean instanceOf(@DottedClassName String dottedSubtype, @DottedClassName String dottedSupertype) { Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); ClassDescriptor subDescriptor = DescriptorFactory.createClassDescriptorFromDottedClassName(dottedSubtype); ClassDescriptor superDescriptor = DescriptorFactory.createClassDescriptorFromDottedClassName(dottedSupertype); try { return subtypes2.isSubtype(subDescriptor, superDescriptor); } catch (ClassNotFoundException e) { AnalysisContext.reportMissingClass(e); return false; } }
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 void visit(JavaClass obj) { isTigerOrHigher = obj.getMajor() >= Const.MAJOR_1_5; try { Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); ClassDescriptor me = getClassDescriptor(); if (subtypes2.isSubtype(me, MAP_ENTRY) && subtypes2.isSubtype(me, ITERATOR)) { bugReporter.reportBug(new BugInstance(this, "PZ_DONT_REUSE_ENTRY_OBJECTS_IN_ITERATORS", NORMAL_PRIORITY) .addClass(this).addString("shouldn't reuse Iterator as a Map.Entry")); } } catch (ClassNotFoundException e) { AnalysisContext.reportMissingClass(e); } }
/** * Get the effective inherited TypeQualifierAnnotation on given instance * method. * * @param o * an XMethod * @param typeQualifierValue * the kind of TypeQualifierValue we are looking for * @return effective TypeQualifierAnnotation inherited from overridden * supertype methods, or null if there is no inherited * TypeQualifierAnnotation */ public static TypeQualifierAnnotation getInheritedTypeQualifierAnnotation(XMethod o, TypeQualifierValue<?> typeQualifierValue) { assert !o.isStatic(); ReturnTypeAnnotationAccumulator accumulator = new ReturnTypeAnnotationAccumulator(typeQualifierValue, o); try { AnalysisContext.currentAnalysisContext().getSubtypes2().traverseSupertypesDepthFirst(o.getClassDescriptor(), accumulator); TypeQualifierAnnotation result = accumulator.getResult().getEffectiveTypeQualifierAnnotation(); if (result == null && accumulator.overrides()) { return TypeQualifierAnnotation.OVERRIDES_BUT_NO_ANNOTATION; } return result; } catch (ClassNotFoundException e) { AnalysisContext.currentAnalysisContext().getLookupFailureCallback().reportMissingClass(e); return null; } }