@Override public final boolean equals(Object obj) { if (obj == null || !(obj instanceof ClassDescriptor)) { return false; } // All instances of ClassDescriptor should be considered // equal if they represent the same class, // even if compared to an object of a different runtime class. return getClassName().equals(((ClassDescriptor) obj).getClassName()); }
@Override public String toString() { return desc.getDottedClassName() + "." + value; }
@Override public @DottedClassName String getPackageName() { return getClassDescriptor().getPackageName(); }
/** * Get a ClassDescriptor for a class name in VM (slashed) format. * * @param className * a class name in VM (slashed) format * @return ClassDescriptor for that class */ public @Nonnull ClassDescriptor getClassDescriptor(@SlashedClassName String className) { assert className.indexOf('.') == -1; ClassDescriptor classDescriptor = classDescriptorMap.get(className); if (classDescriptor == null) { if (MODULE_INFO.getClassName().equals(className)) { // don't allow module info to be added to the map, // which could be used to check referenced classes return MODULE_INFO; } classDescriptor = new ClassDescriptor(className); classDescriptorMap.put(className, classDescriptor); } return classDescriptor; }
public static boolean isStraightGenericMap(ClassDescriptor c) { if (c.matches(Map.class)) { return true; } XClass xc; try { xc = c.getXClass(); } catch (CheckedAnalysisException e) { return false; } String sourceSignature = xc.getSourceSignature(); if (sourceSignature == null) { return false; } if (sourceSignature.startsWith("<")) { Matcher matcher = mapSignaturePattern.matcher(sourceSignature); if (!matcher.matches()) { if (DEBUG) { System.out.println(c + " has a complex generic signature: " + sourceSignature); } // See Bug3470297 and Bug3470297a examples return false; } } return true; }
@Test public void testSimpleName() { ClassDescriptor p = DescriptorFactory.createClassDescriptor("com/bla/Parent"); assertEquals("com/bla/Parent", p.getClassName()); assertEquals("com.bla.Parent", p.getDottedClassName()); assertEquals("Lcom/bla/Parent;", p.getSignature()); assertEquals("com.bla", p.getPackageName()); assertEquals("Parent", p.getSimpleName()); ClassDescriptor c = DescriptorFactory.createClassDescriptor("com/bla/Parent$Child"); assertEquals("com/bla/Parent$Child", c.getClassName()); assertEquals("com.bla.Parent$Child", c.getDottedClassName()); assertEquals("Lcom/bla/Parent$Child;", c.getSignature()); assertEquals("com.bla", c.getPackageName()); assertEquals("Child", c.getSimpleName()); ClassDescriptor a = DescriptorFactory.createClassDescriptor("com/bla/Parent$Child$1"); assertEquals("com/bla/Parent$Child$1", a.getClassName()); assertEquals("com.bla.Parent$Child$1", a.getDottedClassName()); assertEquals("Lcom/bla/Parent$Child$1;", a.getSignature()); assertEquals("com.bla", a.getPackageName()); assertEquals("1", a.getSimpleName()); } }
} 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()) { && !inheritedEquals.getClassDescriptor().getSimpleName().contains("Abstract") && !"java/lang/Enum".equals(inheritedEquals.getClassDescriptor().getClassName())) {
@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) { } } }
@Override public void visitClassContext(ClassContext classContext) { try { cls = classContext.getJavaClass(); ClassDescriptor cd = classContext.getClassDescriptor(); callingClass = cd.getClassName(); callingPackage = cd.getPackageName(); stack = new OpcodeStack(); super.visitClassContext(classContext); } finally { callingPackage = null; stack = null; } }
while (!worklist.isEmpty()) { ClassDescriptor d = worklist.removeFirst(); if (!d.equals(originalClassDescriptor)) { desc = DescriptorFactory.instance().getFieldDescriptor(d.getClassName(), desc.getName(), desc.getSignature(), desc.isStatic());
if ("java/util/Collection".equals(info.interfaceForCall.getClassName()) && "com.google.common.collect.Multiset".equals(invokedMethod.getClassName())) { assert true; String simpleName = info.interfaceForCall.getSimpleName(); if ( simpleName.toLowerCase().endsWith("map") || "Hashtable".equals(simpleName)) { expectedTypeParameters = 2; if (!operandClass.getClassName().startsWith("java/util") && priority == Priorities.HIGH_PRIORITY) { priority = Math.max(priority, Priorities.NORMAL_PRIORITY);
private String findFullyQualifiedSourceFileName(IClassPath classPath, ClassDescriptor classDesc) throws IOException, CheckedAnalysisException { try { // Open and parse the class file to attempt // to discover the source file name. ICodeBaseEntry codeBaseEntry = classPath.lookupResource(classDesc.toResourceName()); ClassParserUsingASM classParser = new ClassParserUsingASM(new ClassReader(codeBaseEntry.openResource()), classDesc, codeBaseEntry); ClassInfo.Builder classInfoBuilder = new ClassInfo.Builder(); classParser.parse(classInfoBuilder); ClassInfo classInfo = classInfoBuilder.build(); // Construct the fully-qualified source file name // based on the package name and source file name. String packageName = classDesc.getPackageName(); String sourceFile = classInfo.getSource(); if (!"".equals(packageName)) { packageName = packageName.replace('.', '/'); packageName += "/"; } String fullyQualifiedSourceFile = packageName + sourceFile; return fullyQualifiedSourceFile; } catch (CheckedAnalysisException e) { errorLogger.logError("Could scan class " + classDesc.toDottedClassName(), e); throw e; } finally { progress.finishClass(); } }
@Override public boolean equals(Object o) { if (!(o instanceof ClassVertex)) { return false; } return classDescriptor.equals(((ClassVertex) o).classDescriptor); }
/** * */ 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); } } }
/** * 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; }
} else { firstCommonSupertype = ObjectTypeFactory.getInstance(lastCommonInBackwardsSearch.getClassDescriptor() .toDottedClassName()); aSuperTypes.remove(objDesc); for (ClassDescriptor c : aSuperTypes) { if (c.getPackageName().equals(aDesc.getPackageName()) || c.getPackageName().equals(bDesc.getPackageName())) { return ObjectTypeFactory.getInstance(c.toDottedClassName()); return ObjectTypeFactory.getInstance(c.toDottedClassName());
@Override public int hashCode() { return classDescriptor.hashCode(); }
@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; }
@Nonnull public BugInstance addType(ClassDescriptor c) { TypeAnnotation typeAnnotation = new TypeAnnotation(c.getSignature()); add(typeAnnotation); return this; }
for (ClassDescriptor subtype : subtypes) { try { XClass xClass = subtype.getXClass(); XMethod subMethod = xClass.findMatchingMethod(xMethod.getMethodDescriptor()); if (subMethod != null) {