@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()); }
public void purge(Collection<ClassDescriptor> unusable) { for (ClassDescriptor c : unusable) { classDescriptorMap.remove(c.getClassName()); dottedClassDescriptorMap.remove(c.getClassName().replace('/', '.')); } }
ClassNameAndSuperclassInfo(ClassDescriptor classDescriptor, ClassDescriptor superclassDescriptor, ClassDescriptor[] interfaceDescriptorList, ICodeBaseEntry codeBaseEntry, int accessFlags, /* TODO: We aren't doing anything with this */ Collection<ClassDescriptor> referencedClassDescriptorList, @Nonnull Set<ClassDescriptor> calledClassDescriptors, int majorVersion, int minorVersion) { super(classDescriptor.getClassName()); this.superclassDescriptor = superclassDescriptor; this.interfaceDescriptorList = interfaceDescriptorList; this.codeBaseEntry = codeBaseEntry; this.accessFlags = accessFlags; if (calledClassDescriptors == null) { throw new NullPointerException("calledClassDescriptors must not be null"); } this.calledClassDescriptors = calledClassDescriptors; this.majorVersion = majorVersion; this.minorVersion = minorVersion; }
public String getSlashedPackageName() { String slashedClassName = getClassDescriptor().getClassName(); int lastSlash = slashedClassName.lastIndexOf('/'); if (lastSlash < 0) { return ""; } else { return slashedClassName.substring(0, lastSlash); } }
public void addCalledMethod(MethodDescriptor m) { assert m.getClassDescriptor().getClassName().indexOf('.') == -1; calledMethods.add(createXMethod(m)); }
/** * 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; }
@Override public void visitClass(ClassDescriptor classDescriptor) throws CheckedAnalysisException { if (!checked) { checked = true; Collection<TypeQualifierValue<?>> allKnownTypeQualifiers = TypeQualifierValue.getAllKnownTypeQualifiers(); int size = allKnownTypeQualifiers.size(); if (size == 1) { TypeQualifierValue<?> value = Util.first(allKnownTypeQualifiers); if (!value.typeQualifier.getClassName().equals(NONNULL_ANNOTATION)) { shouldRunAnalysis = true; } } else if (size > 1) { shouldRunAnalysis = true; } } if (shouldRunAnalysis) { super.visitClass(classDescriptor); } }
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); } }
public static void logMissingAnnotationClass(MissingClassException e) { ClassDescriptor c = e.getClassDescriptor(); if (c.getClassName().startsWith("javax.annotation")) { AnalysisContext.currentAnalysisContext().getLookupFailureCallback().reportMissingClass(c); } }
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; } }
/** * Find a method in given class. * * @param classDesc * the class descriptor * @param methodName * the name of the method * @param methodSig * the signature of the method * @param isStatic * are we looking for a static method? * @return the JavaClassAndMethod, or null if no such method exists in the * class */ public static @CheckForNull XMethod findMethod(ClassDescriptor classDesc, String methodName, String methodSig, boolean isStatic) { if (DEBUG_METHOD_LOOKUP) { System.out.println("Check " + classDesc.getClassName()); } try { XClass xClass = Global.getAnalysisCache().getClassAnalysis(XClass.class, classDesc); return xClass.findMethod(methodName, methodSig, isStatic); } catch (CheckedAnalysisException e) { AnalysisContext.logError("Error looking for " + classDesc + "." + methodName + methodSig, e); return null; } }
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; }
@Override public MethodVisitor visitMethod(int methodAccess, String methodName, String desc, String methodSignature, String[] exceptions) { if ((methodAccess & ACC_STATIC) != 0) { // skip static methods return null; } final XMethod xmethod = xclass.findMethod(methodName, desc, false); if (xmethod == null) { // unable to continue the analysis bugReporter.reportSkippedAnalysis(new MethodDescriptor(xclass.getClassDescriptor().getClassName(), methodName, desc, false)); return null; } return new DetectorNode(methodAccess, methodName, desc, methodSignature, exceptions, xmethod); }
@Override public FieldDescriptor getFieldDescriptor() { return DescriptorFactory.instance().getFieldDescriptor(getClassDescriptor().getClassName(), getName(), getSignature(), isStatic()); } }
ClassDescriptor d = worklist.removeFirst(); if (!d.equals(originalClassDescriptor)) { desc = DescriptorFactory.instance().getFieldDescriptor(d.getClassName(), desc.getName(), desc.getSignature(), desc.isStatic());
@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) { } } }
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")
@Override public void sawOpcode(int seen) { if(skip) { return; } if(isBranch(seen) || seen == Const.ATHROW || isReturn(seen)) { skip = true; } if(seen == Const.PUTFIELD) { XField xField = getXFieldOperand(); if(xField != null && xField.getClassDescriptor().getClassName().equals(getClassName())) { Item val = getStack().getStackItem(0); if(val.isInitialParameter()) { reporter.reportBug(new BugInstance("ME_ENUM_FIELD_SETTER", NORMAL_PRIORITY).addClassAndMethod(this).addField(xField) .addSourceLine(this)); } } } } }
private MethodCall getMethodCall(MethodDescriptor methodDescriptorOperand) { Item objItem = getStack().getStackItem(getNumberArguments(methodDescriptorOperand.getSignature())); if (isNew(objItem)) { return new MethodCall(methodDescriptorOperand, TARGET_NEW); } if (objItem.getRegisterNumber() == 0 && !getMethod().isStatic()) { return new MethodCall(methodDescriptorOperand, constructor ? TARGET_NEW : TARGET_THIS); } XField xField = objItem.getXField(); if (xField != null) { if (classInit && xField.isStatic() && xField.getClassDescriptor().getClassName().equals(getClassName())) { return new MethodCall(methodDescriptorOperand, TARGET_NEW); } if (!getMethodDescriptor().isStatic() && objItem.getFieldLoadedFromRegister() == 0 && allowedFields.contains(xField.getFieldDescriptor())) { fieldsModifyingMethods.add(getMethodDescriptor()); return new MethodCall(methodDescriptorOperand, xField.getFieldDescriptor()); } } return new MethodCall(methodDescriptorOperand, TARGET_OTHER); }
@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()); } }