public void setCalledFromSuperConstructor(ProgramPoint from, XMethod calledFromConstructor) { Set<ProgramPoint> set = selfMethodsCalledFromConstructor.get(calledFromConstructor); if (set == null) { set = new HashSet<>(); selfMethodsCalledFromConstructor.put(calledFromConstructor, set); } set.add(from); callsOverriddenMethodsFromConstructor.add(from.method.getClassDescriptor()); }
public static Set<XMethod> findSuperMethods(XMethod m) { Set<XMethod> result = new HashSet<>(); findSuperMethods(m.getClassDescriptor(), m, result); result.remove(m); return result; }
public Set<ProgramPoint> getCalledFromSuperConstructor(ClassDescriptor superClass, XMethod calledFromConstructor) { if (!callsOverriddenMethodsFromConstructor.contains(superClass)) { return Collections.emptySet(); } for (Map.Entry<XMethod, Set<ProgramPoint>> e : selfMethodsCalledFromConstructor.entrySet()) { XMethod m = e.getKey(); if (m.getName().equals(calledFromConstructor.getName()) && m.getClassDescriptor().equals(calledFromConstructor.getClassDescriptor())) { String sig1 = m.getSignature(); String sig2 = calledFromConstructor.getSignature(); sig1 = sig1.substring(0, sig1.indexOf(')')); sig2 = sig2.substring(0, sig2.indexOf(')')); if (sig1.equals(sig2)) { return e.getValue(); } } } return Collections.emptySet(); }
public static Set<XMethod> resolveVirtualMethodCallTargets(XMethod target, boolean receiverTypeIsExact, boolean invokeSpecial) throws ClassNotFoundException { return resolveVirtualMethodCallTargets(target.getClassDescriptor(), target.getName(), target.getSignature(), receiverTypeIsExact, invokeSpecial); }
for(XMethod superMethod : superMethods) { try { subtypes.addAll(subtypes2.getSubtypes(superMethod.getClassDescriptor())); } catch (ClassNotFoundException e) { subtypes.remove(xMethod.getClassDescriptor()); for (ClassDescriptor subtype : subtypes) { try {
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; }
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; }
private boolean checkForWeirdEquals(String lhsSig, String rhsSig, Set<XMethod> targets) { boolean allOk = false; try { ClassSummary classSummary = AnalysisContext.currentAnalysisContext().getClassSummary(); ClassDescriptor expectedClassDescriptor = DescriptorFactory.createClassDescriptorFromSignature(lhsSig); ClassDescriptor actualClassDescriptor = DescriptorFactory.createClassDescriptorFromSignature(rhsSig); targets.addAll(Hierarchy2.resolveVirtualMethodCallTargets(expectedClassDescriptor, "equals", "(Ljava/lang/Object;)Z", false, false)); allOk = targets.size() > 0; for (XMethod m2 : targets) { if (!classSummary.mightBeEqualTo(m2.getClassDescriptor(), actualClassDescriptor)) { allOk = false; } } } catch (ClassNotFoundException e) { AnalysisContext.reportMissingClass(e); } return allOk; }
XMethod rvo = rvo1 == null ? rvo2 : rvo1; if (lowerBound instanceof Comparable && upperBound != null && upperBound.getClass() == lowerBound.getClass() && rvo.getClassDescriptor().getClassName().equals("java/lang/Math") && (rvo.getName().equals("max") || rvo.getName().equals("min"))) { @SuppressWarnings("unchecked")
createdObligation = database.getFactory().getObligationByType(xmethod.getClassDescriptor()); } else {
/** * Constructor. Creates an entry which matches the given XMethod. * * @param xmethod * an XMethod * @param action * ActionType (ADD or DEL, depending on whether obligation is * added or deleted) * @param entryType * entry type * @param obligations * Obligation to be added or deleted */ public MatchMethodEntry(XMethod xmethod, ObligationPolicyDatabaseActionType action, ObligationPolicyDatabaseEntryType entryType, Obligation... obligations) { this(new SubtypeTypeMatcher(xmethod.getClassDescriptor()), new ExactStringMatcher(xmethod.getName()), new ExactStringMatcher(xmethod.getSignature()), xmethod.isStatic(), action, entryType, obligations); }
if ("<init>".equals(xmethod.getName()) && xmethod.getClassDescriptor().isAnonymousClass()) XClass xclass = Global.getAnalysisCache().getClassAnalysis(XClass.class, xmethod.getClassDescriptor()); stopAtClassScope = xclass.isPrivate(); } catch (CheckedAnalysisException e) {
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; } }
.traverseSupertypesDepthFirst(xmethod.getClassDescriptor(), visitor); } catch (ClassNotFoundException e) { AnalysisContext.currentAnalysisContext().getLookupFailureCallback().reportMissingClass(e);
/** * Get the effective inherited TypeQualifierAnnotation on the given instance * method parameter. * * @param xmethod * an instance method * @param parameter * a parameter (0 == first parameter) * @param typeQualifierValue * the kind of TypeQualifierValue we are looking for * @return effective inherited TypeQualifierAnnotation on the parameter, or * null if there is not effective TypeQualifierAnnotation */ public static @CheckForNull TypeQualifierAnnotation getInheritedTypeQualifierAnnotation(XMethod xmethod, int parameter, TypeQualifierValue<?> typeQualifierValue) { assert !xmethod.isStatic(); ParameterAnnotationAccumulator accumulator = new ParameterAnnotationAccumulator(typeQualifierValue, xmethod, parameter); try { AnalysisContext.currentAnalysisContext().getSubtypes2().traverseSupertypesDepthFirst(xmethod.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; } }
continue locationLoop; XClass xc = AnalysisContext.currentXFactory().getXClass(m.getClassDescriptor()); if (!(inv instanceof INVOKESTATIC) && !(m.isFinal() || xc.isFinal())) { priority = Priorities.NORMAL_PRIORITY; if (!AnalysisContext.currentAnalysisContext().getSubtypes2().hasSubtypes(m.getClassDescriptor())) { continue locationLoop;
@Override public boolean visitClass(ClassDescriptor classDescriptor, XClass xclass) { assert xclass != null; String methodSignature = xmethod.getSignature(); XMethod bridgedFrom = xmethod.bridgeFrom(); // See if this class has an overridden method XMethod xm = xclass.findMethod(xmethod.getName(), methodSignature, false); if (xm == null && bridgedFrom != null && !classDescriptor.equals(xmethod.getClassDescriptor())) { methodSignature = bridgedFrom.getSignature(); xm = xclass.findMethod(xmethod.getName(), methodSignature, false); } if (xm != null) { return visitOverriddenMethod(xm) || bridgedFrom != null; } else { // Even though this particular class doesn't contain the method // we're // looking for, a superclass might, so we need to keep going. return true; } }
&& subtypes2.isSubtype(called.getClassDescriptor(), getClassDescriptor())) { fieldSummary.setCalledFromSuperConstructor(new ProgramPoint(this), called);
/** * 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; } }
} else { String callReturnClass = callSeen.getName().equals(Const.CONSTRUCTOR_NAME) ? callSeen.getClassDescriptor().getClassName() : ClassName.fromFieldSignature(callReturnType.getSignature());