boolean isChecked(String c) { if (!causes.add(c)) { return checkedCauses.contains(c); } try { if (Hierarchy.isSubtype(c, "java.lang.Exception") && !Hierarchy.isSubtype(c, "java.lang.RuntimeException")) { checkedCauses.add(c); return true; } } catch (ClassNotFoundException e) { bugReporter.reportMissingClass(e); } return false; }
@Override public boolean match(String s) { try { return Hierarchy.isSubtype(s, className); } catch (ClassNotFoundException e) { AnalysisContext.reportMissingClass(e); return false; } } }
private boolean isThread(String clazz) { try { return Hierarchy.isSubtype(clazz, "java.lang.Thread"); } catch (ClassNotFoundException e) { bugReporter.reportMissingClass(e); return false; } }
static boolean areRelated(String sig, String superSig) { try { if (sig.equals(superSig)) { return true; } if (sig.charAt(0) == 'L' && superSig.charAt(0) == 'L') { sig = sig.substring(1, sig.length() - 1); superSig = superSig.substring(1, superSig.length() - 1); return Hierarchy.isSubtype(sig, superSig); } } catch (ClassNotFoundException e) { AnalysisContext.reportMissingClass(e); } return false; } }
/** * Test if the given class is a subtype of ONE of the super classes given. * <br/> * The following test that the class is a subclass of Hashtable. * <pre> * boolean isHashtable = InterfaceUtils.isSubtype( classThatCouldBeAHashTable, "java.util.Hashtable"); * </pre> * * @param className Class to test * @param superClasses If classes extends or implements those classes * @return */ public static boolean isSubtype(String className, String... superClasses) { for(String potentialSuperClass : superClasses) { try { if(Hierarchy.isSubtype(className, potentialSuperClass)) { return true; } } catch (ClassNotFoundException e) { AnalysisContext.reportMissingClass(e); } } return false; } }
/** * Look up an Obligation by type. This returns the first Obligation that is * a supertype of the type given (meaning that the given type could be an * instance of the returned Obligation). * * @param type * a type * @return an Obligation that is a supertype of the given type, or null if * there is no such Obligation * @throws ClassNotFoundException */ public @CheckForNull Obligation getObligationByType(ObjectType type) throws ClassNotFoundException { for (Iterator<Obligation> i = obligationIterator(); i.hasNext();) { Obligation obligation = i.next(); if (Hierarchy.isSubtype(type, obligation.getType())) { return obligation; } } return null; }
if (!Hierarchy.isSubtype(expectedType, actualType) && !Hierarchy.isSubtype(actualType, expectedType)) { if (Hierarchy.isSubtype(expectedType, GWT_JAVASCRIPTOBJECT_TYPE) && Hierarchy.isSubtype(actualType, GWT_JAVASCRIPTOBJECT_TYPE)) { return SEEMS_OK; && (Hierarchy.isSubtype(expectedType, COLLECTION_TYPE) || Hierarchy.isSubtype(expectedType, MAP_TYPE))) { List<? extends ReferenceType> lhsParameters = ((GenericObjectType) expectedType).getParameters(); List<? extends ReferenceType> rhsParameters = ((GenericObjectType) actualType).getParameters();
@Override public boolean mightCloseResource(BasicBlock basicBlock, InstructionHandle handle, ConstantPoolGen cpg) throws DataflowAnalysisException { InvokeInstruction inv = toInvokeInstruction(handle.getInstruction()); if (inv == null) { return false; } String className = inv.getClassName(cpg); String methodName = inv.getName(cpg); String methodSig = inv.getSignature(cpg); try { if ("unlock".equals(methodName) && "()V".equals(methodSig) && Hierarchy.isSubtype(className, "java.util.concurrent.locks.Lock")) { return true; } } catch (ClassNotFoundException e) { lookupFailureCallback.reportMissingClass(e); } return false; }
@Override public void visitClassContext(ClassContext classContext) { JavaClass javaClass = classContext.getJavaClass(); try { if(!Hierarchy.isSubtype(javaClass.getClassName(), "javax.servlet.http.HttpServlet")) { return; } } catch (ClassNotFoundException e) { AnalysisContext.reportMissingClass(e); } for (Method m : javaClass.getMethods()) { try { analyzeMethod(m, classContext); } catch (CFGBuilderException e) { } catch (DataflowAnalysisException e) { } } }
@Override public void visitClassContext(ClassContext classContext) { JavaClass javaClass = classContext.getJavaClass(); try { if (!Hierarchy.isSubtype(javaClass.getClassName(), "javax.servlet.http.HttpServlet")) { return; } } catch (ClassNotFoundException e) { AnalysisContext.reportMissingClass(e); } for (Method m : javaClass.getMethods()) { try { analyzeMethod(m, classContext); } catch (CFGBuilderException | DataflowAnalysisException e) { AnalysisContext.logError("Cannot analyze method", e); } } }
if (!Hierarchy.isSubtype(classType, baseClassType)) { return null;
if (leastSupertype != null && Hierarchy.isSubtype(leastSupertype, fieldType)) { loadType = leastSupertype;
@Override public Lock isResourceCreation(BasicBlock basicBlock, InstructionHandle handle, ConstantPoolGen cpg) throws DataflowAnalysisException { InvokeInstruction inv = toInvokeInstruction(handle.getInstruction()); if (inv == null) { return null; } String className = inv.getClassName(cpg); String methodName = inv.getName(cpg); String methodSig = inv.getSignature(cpg); try { if ("lock".equals(methodName) && "()V".equals(methodSig) && Hierarchy.isSubtype(className, "java.util.concurrent.locks.Lock")) { Location location = new Location(handle, basicBlock); ValueNumberFrame frame = vnaDataflow.getFactAtLocation(location); ValueNumber lockValue = frame.getTopValue(); if (DEBUG) { System.out.println("Lock value is " + lockValue.getNumber() + ", frame=" + frame.toString()); } if (DEBUG) { ++numAcquires; } return new Lock(location, className, lockValue); } } catch (ClassNotFoundException e) { lookupFailureCallback.reportMissingClass(e); } return null; }
return null; if (!Hierarchy.isSubtype(fieldClass, streamBaseClass)) { return null;
@Override public void sawOpcode(int seen) { if (seen == Const.INVOKEVIRTUAL && "start".equals(getNameConstantOperand()) && "()V".equals(getSigConstantOperand())) { try { if (Hierarchy.isSubtype(getDottedClassConstantOperand(), "java.lang.Thread")) { int priority = Priorities.NORMAL_PRIORITY; if (getPC() + 4 >= getCode().getCode().length) { priority = Priorities.LOW_PRIORITY; } BugInstance bug = new BugInstance(this, "SC_START_IN_CTOR", priority).addClassAndMethod(this) .addCalledMethod(this); Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); Set<ClassDescriptor> directSubtypes = subtypes2.getDirectSubtypes(getClassDescriptor()); if (!directSubtypes.isEmpty()) { for (ClassDescriptor sub : directSubtypes) { bug.addClass(sub).describe(ClassAnnotation.SUBCLASS_ROLE); } bug.setPriority(Priorities.HIGH_PRIORITY); } bugAccumulator.accumulateBug(bug, this); } } catch (ClassNotFoundException e) { bugReporter.reportMissingClass(e); } } } }
@Override public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg, RepositoryLookupFailureCallback lookupFailureCallback) { Instruction ins = location.getHandle().getInstruction(); try { if (ins instanceof InvokeInstruction) { if (!Hierarchy.isSubtype(type, baseClassType)) { return null; } Stream stream = new Stream(location, type.getClassName(), baseClassType.getClassName()).setIsOpenOnCreation(true) .setIgnoreImplicitExceptions(true); if (bugType != null) { stream.setInteresting(bugType); } return stream; } } catch (ClassNotFoundException e) { lookupFailureCallback.reportMissingClass(e); } return null; } }
private void checkMonitorWait() { try { TypeDataflow typeDataflow = getClassContext().getTypeDataflow(getMethod()); TypeDataflow.LocationAndFactPair pair = typeDataflow.getLocationAndFactForInstruction(getPC()); if (pair == null) { return; } Type receiver = pair.frame.getInstance(pair.location.getHandle().getInstruction(), getClassContext() .getConstantPoolGen()); if (!(receiver instanceof ReferenceType)) { return; } if (Hierarchy.isSubtype((ReferenceType) receiver, CONDITION_TYPE)) { accumulator.accumulateBug( new BugInstance(this, "DM_MONITOR_WAIT_ON_CONDITION", HIGH_PRIORITY).addClassAndMethod(this), this); } } catch (ClassNotFoundException e) { bugReporter.reportMissingClass(e); } catch (DataflowAnalysisException e) { bugReporter.logError("Exception caught by DumbMethods", e); } catch (CFGBuilderException e) { bugReporter.logError("Exception caught by DumbMethods", e); } }