@Override public boolean equals(Object o) { if (!(o instanceof ClassVertex)) { return false; } return classDescriptor.equals(((ClassVertex) o).classDescriptor); }
@Override public boolean equals(Object o) { if (!(o instanceof TypeQualifierValue)) { return false; } TypeQualifierValue<?> other = (TypeQualifierValue<?>) o; return typeQualifier.equals(other.typeQualifier) && Objects.equals(value, other.value); }
@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof EnumValue)) { return false; } EnumValue other = (EnumValue) obj; return this.desc.equals(other.desc) && this.value.equals(other.value); }
public void checksForEqualTo(ClassDescriptor checker, ClassDescriptor checkee) { ClassDescriptor existing = map.get(checker); if (checkee.equals(existing)) { return; } else if (existing != null) { veryFunky.add(checker); } else { map.put(checker, checkee); } }
public boolean mightBeEqualTo(ClassDescriptor checker, ClassDescriptor checkee) { return checkee.equals(map.get(checker)) || veryFunky.contains(checker); }
/** * Determine whether or not given TypeQualifierValue has multiple variants. * I.e., if Color is a type qualifier having values RED, GREEN, and BLUE, * then there are 3 variants, Color(RED), Color(GREEN), and COLOR(BLUE). * * @param tqv * a TypeQualifierValue * @return true if there are multiple variants of this type qualifier, false * otherwise */ public static boolean hasMultipleVariants(TypeQualifierValue<?> tqv) { int count = 0; for (TypeQualifierValue<?> t : instance.get().allKnownTypeQualifiers) { if (t.typeQualifier.equals(tqv.typeQualifier)) { count++; } } return count > 1; }
/** * Get the "complementary" TypeQualifierValues for given exclusive type * qualifier. * * @param tqv * a type qualifier (which must be exclusive) * @return Collection of complementary exclusive type qualifiers */ public static Collection<TypeQualifierValue<?>> getComplementaryExclusiveTypeQualifierValue(TypeQualifierValue<?> tqv) { assert tqv.isExclusiveQualifier(); LinkedList<TypeQualifierValue<?>> result = new LinkedList<>(); for (TypeQualifierValue<?> t : instance.get().allKnownTypeQualifiers) { // // Any TypeQualifierValue with the same // annotation class but a different value is a complementary // type qualifier. // if (t.typeQualifier.equals(tqv.typeQualifier) && !Objects.equals(t.value, tqv.value)) { result.add(t); } } return result; }
@Override public XMethod findMethod(MethodDescriptor descriptor) { if (!descriptor.getClassDescriptor().equals(this)) { throw new IllegalArgumentException(); } return findMatchingMethod(descriptor); }
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 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; }
@Override public ClassNameAndSuperclassInfo analyze(IAnalysisCache analysisCache, ClassDescriptor descriptor) throws CheckedAnalysisException { // Get InputStream reading from class data ClassData classData = analysisCache.getClassAnalysis(ClassData.class, descriptor); DataInputStream classDataIn = new DataInputStream(new ByteArrayInputStream(classData.getData())); // Read the class info ClassParserInterface parser = new ClassParser(classDataIn, descriptor, classData.getCodeBaseEntry()); ClassNameAndSuperclassInfo.Builder classInfoBuilder = new ClassNameAndSuperclassInfo.Builder(); parser.parse(classInfoBuilder); ClassNameAndSuperclassInfo classInfo = classInfoBuilder.build(); if (!classInfo.getClassDescriptor().equals(descriptor)) { throw new ClassNameMismatchException(descriptor, classInfo.getClassDescriptor(), classData.getCodeBaseEntry()); } return classInfo; }
while (!worklist.isEmpty()) { ClassDescriptor d = worklist.removeFirst(); if (!d.equals(originalClassDescriptor)) { desc = DescriptorFactory.instance().getFieldDescriptor(d.getClassName(), desc.getName(), desc.getSignature(), desc.isStatic());
if (o instanceof EnumValue) { EnumValue e = (EnumValue) o; if (e.desc.equals(elementTypeDescriptor) && e.value.equals(defaultFor.name())) { for (ClassDescriptor d : c.getAnnotationDescriptors()) { if (!d.equals(typeQualifierDefault)) { resolveTypeQualifierNicknames(c.getAnnotation(d), result, new LinkedList<ClassDescriptor>());
/** * Adjust the priority of a warning about to be reported. * * @param priority * initial priority * @return adjusted priority */ private int adjustPriority(int priority) { try { Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); if (!subtypes2.hasSubtypes(getClassDescriptor())) { priority++; } else { Set<ClassDescriptor> mySubtypes = subtypes2.getSubtypes(getClassDescriptor()); String myPackagename = getThisClass().getPackageName(); for (ClassDescriptor c : mySubtypes) { if (c.equals(getClassDescriptor())) { continue; } if (!c.getPackageName().equals(myPackagename)) { priority--; break; } } } } catch (ClassNotFoundException e) { bugReporter.reportMissingClass(e); } return priority; }
@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; } }
public static IncompatibleTypes getPriorityForAssumingCompatible(boolean pointerEquality, ClassDescriptor lhsDescriptor, ClassDescriptor rhsDescriptor) throws CheckedAnalysisException, ClassNotFoundException { if (lhsDescriptor.equals(rhsDescriptor)) { return SEEMS_OK;
@Override public ClassInfo analyze(IAnalysisCache analysisCache, ClassDescriptor descriptor) throws CheckedAnalysisException { if (descriptor instanceof ClassInfo) { return (ClassInfo) descriptor; } ClassData classData; try { classData = analysisCache.getClassAnalysis(ClassData.class, descriptor); } catch (edu.umd.cs.findbugs.classfile.MissingClassException e) { if (!"package-info".equals(descriptor.getSimpleName())) { throw e; } ClassInfo.Builder builder = new ClassInfo.Builder(); builder.setClassDescriptor(descriptor); builder.setAccessFlags(1536); return builder.build(); } // Read the class info FBClassReader reader = analysisCache.getClassAnalysis(FBClassReader.class, descriptor); ClassParserInterface parser = new ClassParserUsingASM(reader, descriptor, classData.getCodeBaseEntry()); ClassInfo.Builder classInfoBuilder = new ClassInfo.Builder(); parser.parse(classInfoBuilder); ClassInfo classInfo = classInfoBuilder.build(); if (!classInfo.getClassDescriptor().equals(descriptor)) { throw new ClassNameMismatchException(descriptor, classInfo.getClassDescriptor(), classData.getCodeBaseEntry()); } return classInfo; }
@Override public void parse(final ClassNameAndSuperclassInfo.Builder builder) throws InvalidClassFileFormatException { builder.setCodeBaseEntry(codeBaseEntry); builder.setAccessFlags(javaClass.getAccessFlags()); ClassDescriptor classDescriptor = DescriptorFactory.createClassDescriptorFromDottedClassName(javaClass.getClassName()); if (expectedClassDescriptor != null && expectedClassDescriptor.equals(classDescriptor)) { throw new InvalidClassFileFormatException("Expected " + expectedClassDescriptor, classDescriptor, codeBaseEntry); } builder.setClassDescriptor(classDescriptor); builder.setSuperclassDescriptor(DescriptorFactory.createClassDescriptorFromDottedClassName(javaClass.getSuperclassName())); String[] allInterfaces = javaClass.getInterfaceNames(); ClassDescriptor[] allInterfaceDescriptiors; if (allInterfaces.length == 0) { allInterfaceDescriptiors = ClassDescriptor.EMPTY_ARRAY; } else { allInterfaceDescriptiors = new ClassDescriptor[allInterfaces.length]; for (int i = 0; i < allInterfaces.length; i++) { allInterfaceDescriptiors[i] = DescriptorFactory.createClassDescriptorFromDottedClassName(allInterfaces[i]); } } builder.setInterfaceDescriptorList(allInterfaceDescriptiors); }
/** * */ private void check(ClassDescriptor c) { OpcodeStack.Item item = stack.getStackItem(0); if (item.isInitialParameter() && item.getRegisterNumber() == 1) { ClassDescriptor thisClassDescriptor = getClassDescriptor(); if (c.equals(thisClassDescriptor)) { return; } Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); try { if (!c.isArray() && (subtypes2.isSubtype(c, thisClassDescriptor) || subtypes2.isSubtype(thisClassDescriptor, c))) { return; } Type thisType = Type.getType(thisClassDescriptor.getSignature()); Type cType = Type.getType(c.getSignature()); IncompatibleTypes check = IncompatibleTypes.getPriorityForAssumingCompatible(thisType, cType, false); int priority = check.getPriority(); if ("java/lang/Object".equals(getSuperclassName()) && ClassName.isLocalOrAnonymous(getClassName())) { priority++; } bugAccumulator.accumulateBug(new BugInstance(this, "EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS", priority) .addClassAndMethod(this).addType(c).describe(TypeAnnotation.FOUND_ROLE), this); classSummary.checksForEqualTo(thisClassDescriptor, c); } catch (ClassNotFoundException e) { bugReporter.reportMissingClass(e); } } }