public HierarchyIterator(@Nonnull XClass xclass) { interfacesToVisit = new LinkedList<>(Arrays.asList(xclass.getInterfaceDescriptorList())); visited = new HashSet<>(); superclass = getClassInfo(xclass.getSuperclassDescriptor()); }
public static XClass findSuperImplementor(XClass clazz, String name, String signature, boolean isStatic) throws CheckedAnalysisException { ClassDescriptor superclassDescriptor = clazz.getSuperclassDescriptor(); if (superclassDescriptor == null) { return clazz; } return findImplementor(getXClass(superclassDescriptor), name, signature, isStatic); }
public XClass next() { while (!interfacesToVisit.isEmpty()) { ClassDescriptor interfaceDescr = interfacesToVisit.poll(); if (visited.add(interfaceDescr)) { XClass xinterface = getClassInfo(interfaceDescr); if(xinterface != null){ interfacesToVisit.addAll(Arrays.asList(xinterface.getInterfaceDescriptorList())); return xinterface; } } } // no interfaces => check super classes if (superclass == null) { return null; } XClass currentSuperclass = superclass; // compute next one superclass = getClassInfo(superclass.getSuperclassDescriptor()); if(superclass != null){ interfacesToVisit = new LinkedList<>(Arrays.asList(superclass.getInterfaceDescriptorList())); } return currentSuperclass; } }
public static @CheckForNull XMethod findFirstSuperMethod(XMethod m) { try { @CheckForNull ClassDescriptor c = m.getClassDescriptor(); XClass xc = getXClass(c); c = xc.getSuperclassDescriptor(); while (c != null) { xc = getXClass(c); XMethod xm = xc.findMatchingMethod(m.getMethodDescriptor()); if (xm != null) { return xm; } c = xc.getSuperclassDescriptor(); } } catch (CheckedAnalysisException e) { AnalysisContext.logError("Error finding super methods for " + m, e); } return null; }
/** * Determine whether the class descriptor ultimately inherits from * java.lang.Exception * * @param d * class descriptor we want to check * @return true iff the descriptor ultimately inherits from Exception */ private static boolean mightInheritFromException(ClassDescriptor d) { while (d != null) { try { if ("java.lang.Exception".equals(d.getDottedClassName())) { return true; } XClass classNameAndInfo = Global.getAnalysisCache().getClassAnalysis(XClass.class, d); d = classNameAndInfo.getSuperclassDescriptor(); } catch (CheckedAnalysisException e) { return true; // don't know } } return false; }
public boolean callsOverriddenMethodsFromSuperConstructor(ClassDescriptor c) { try { while (true) { XClass cx = Global.getAnalysisCache().getClassAnalysis(XClass.class, c); c = cx.getSuperclassDescriptor(); if (c == null) { return false; } if (callsOverriddenMethodsFromConstructor(c)) { return true; } } } catch (CheckedAnalysisException e) { return false; } }
private boolean isJunit3TestCase(XClass jClass) throws ClassNotFoundException { ClassDescriptor sDesc = jClass.getSuperclassDescriptor(); if (sDesc == null) { return false; } String sName = sDesc.getClassName(); if (sName.equals("junit/framework/TestCase")) { return true; } if (sName.equals("java/lang/Object")) { return false; } try { XClass sClass = Global.getAnalysisCache().getClassAnalysis(XClass.class, sDesc); if (sClass == null) { return false; } return isJunit3TestCase(sClass); } catch (CheckedAnalysisException e) { return false; } }
static @Nonnull XMethod getInvokedMethod(XClass xClass, String name, String sig, boolean isStatic) throws CheckedAnalysisException { IAnalysisCache cache = Global.getAnalysisCache(); while (true) { XMethod result = xClass.findMethod(name, sig, isStatic); if (result != null) { return result; } if (isStatic) { throw new CheckedAnalysisException(); } ClassDescriptor superclassDescriptor = xClass.getSuperclassDescriptor(); if (superclassDescriptor == null) { throw new CheckedAnalysisException(); } xClass = cache.getClassAnalysis(XClass.class, superclassDescriptor); } }
private static void findSuperMethods(@CheckForNull ClassDescriptor c, XMethod m, Set<XMethod> accumulator) { if (c == null) { return; } try { XClass xc = getXClass(c); XMethod xm = xc.findMatchingMethod(m.getMethodDescriptor()); if (xm != null && !accumulator.add(xm)) { return; } findSuperMethods(xc.getSuperclassDescriptor(), m, accumulator); for (ClassDescriptor i : xc.getInterfaceDescriptorList()) { findSuperMethods(i, m, accumulator); } if (!accumulator.add(m)) { return; } } catch (CheckedAnalysisException e) { AnalysisContext.logError("Error finding super methods for " + m, e); } }
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; }
d = classNameAndInfo.getSuperclassDescriptor(); for (ClassDescriptor i : is) { if ("java.util.Map".equals(i.getDottedClassName())) {
private void superClinitCall() { ClassDescriptor superclassDescriptor = getXClass().getSuperclassDescriptor(); if(superclassDescriptor != null && !superclassDescriptor.getClassName().equals("java/lang/Object")) { sawCall(new MethodCall(new MethodDescriptor(superclassDescriptor.getClassName(), Const.STATIC_INITIALIZER_NAME, "()V", true), TARGET_THIS), false); } }
/** * Add supertype edges to the InheritanceGraph for given ClassVertex. If any * direct supertypes have not been processed, add them to the worklist. * * @param vertex * a ClassVertex whose supertype edges need to be added * @param workList * work list of ClassVertexes that need to have their supertype * edges added */ private void addSupertypeEdges(ClassVertex vertex, LinkedList<XClass> workList) { XClass xclass = vertex.getXClass(); // Direct superclass ClassDescriptor superclassDescriptor = xclass.getSuperclassDescriptor(); if (superclassDescriptor != null) { addInheritanceEdge(vertex, superclassDescriptor, false, workList); } // Directly implemented interfaces for (ClassDescriptor ifaceDesc : xclass.getInterfaceDescriptorList()) { addInheritanceEdge(vertex, ifaceDesc, true, workList); } }
break; ClassDescriptor superClass = xClass.getSuperclassDescriptor(); if (superClass != null) { worklist.add(superClass);
@Override public void sawOpcode(int seen) { try { if(seen == INVOKEVIRTUAL && REDIRECT_METHODS.contains(getNameConstantOperand())) { if("scala/runtime/AbstractFunction0".equals(getClassDescriptor().getXClass().getSuperclassDescriptor().getClassName())) { bugReporter.reportBug(new BugInstance(this, PLAY_UNVALIDATED_REDIRECT_TYPE, Priorities.NORMAL_PRIORITY) // .addClass(this).addMethod(this).addSourceLine(this).addString(getNameConstantOperand())); // } } } catch (CheckedAnalysisException e) { } } }
private void traverseSupertypesDepthFirstHelper(ClassDescriptor cur, SupertypeTraversalVisitor visitor, Set<ClassDescriptor> seen) throws ClassNotFoundException { if (seen.contains(cur)) { return; } seen.add(cur); ClassVertex vertex = resolveClassVertex(cur); if (!vertex.isResolved()) { // Unknown class - so, we don't know its immediate supertypes return; } if (!visitor.visitClass(vertex.getClassDescriptor(), vertex.getXClass())) { // Visitor doesn't want to continue on this path return; } // Advance to direct superclass ClassDescriptor superclassDescriptor = vertex.getXClass().getSuperclassDescriptor(); if (superclassDescriptor != null) { traverseSupertypesDepthFirstHelper(superclassDescriptor, visitor, seen); } // Advance to directly-implemented interfaces for (ClassDescriptor ifaceDesc : vertex.getXClass().getInterfaceDescriptorList()) { traverseSupertypesDepthFirstHelper(ifaceDesc, visitor, seen); } }
public boolean isSubtype(ClassDescriptor subDesc, ClassDescriptor... superDesc) throws ClassNotFoundException { for (ClassDescriptor s : superDesc) { if (subDesc.equals(s)) { return true; } } XClass xclass = AnalysisContext.currentXFactory().getXClass(subDesc); if (xclass != null) { ClassDescriptor xSuper = xclass.getSuperclassDescriptor(); for (ClassDescriptor s : superDesc) { if (s.equals(xSuper)) { return true; } } } SupertypeQueryResults supertypeQueryResults = getSupertypeQueryResults(subDesc); for (ClassDescriptor s : superDesc) { if (supertypeQueryResults.containsType(s)) { return true; } } return false; }
public boolean isCalledDirectlyOrIndirectly(XMethod m) { if (isCalled(m)) { return true; } if (m.isStatic() || m.isPrivate() || Const.CONSTRUCTOR_NAME.equals(m.getName())) { return false; } try { IAnalysisCache analysisCache = Global.getAnalysisCache(); XClass clazz = analysisCache.getClassAnalysis(XClass.class, m.getClassDescriptor()); if (isCalledDirectlyOrIndirectly(clazz.getSuperclassDescriptor(), m)) { return true; } for (ClassDescriptor i : clazz.getInterfaceDescriptorList()) { if (isCalledDirectlyOrIndirectly(i, m)) { return true; } } return false; } catch (edu.umd.cs.findbugs.classfile.MissingClassException e) { // AnalysisContext.reportMissingClass(e.getClassNotFoundException()); return false; } catch (MissingClassException e) { AnalysisContext.reportMissingClass(e.getClassNotFoundException()); return false; } catch (Exception e) { AnalysisContext.logError("Error checking to see if " + m + " is called (" + e.getClass().getCanonicalName() + ")", e); return false; } }
private boolean isCalledDirectlyOrIndirectly(@CheckForNull ClassDescriptor clazzDescriptor, XMethod m) throws CheckedAnalysisException { if (clazzDescriptor == null) { return false; } IAnalysisCache analysisCache = Global.getAnalysisCache(); XClass clazz = analysisCache.getClassAnalysis(XClass.class, clazzDescriptor); XMethod m2 = clazz.findMethod(m.getName(), m.getSignature(), m.isStatic()); if (m2 != null && isCalled(m2)) { return true; } if (isCalledDirectlyOrIndirectly(clazz.getSuperclassDescriptor(), m)) { return true; } for (ClassDescriptor i : clazz.getInterfaceDescriptorList()) { if (isCalledDirectlyOrIndirectly(i, m)) { return true; } } return false; }