@Override public void logError(String message, Throwable e) { Global.getAnalysisCache().getErrorLogger().logError(message, e); }
@Override public void reportMissingClass(ClassDescriptor classDescriptor) { Global.getAnalysisCache().getErrorLogger().reportMissingClass(classDescriptor); }
@Override public void reportSkippedAnalysis(MethodDescriptor method) { Global.getAnalysisCache().getErrorLogger().reportSkippedAnalysis(method); }
@Override public void logError(String message) { Global.getAnalysisCache().getErrorLogger().logError(message); }
@Override public void reportMissingClass(ClassNotFoundException ex) { Global.getAnalysisCache().getErrorLogger().reportMissingClass(ex); }
@Override public void reportSkippedAnalysis(MethodDescriptor method) { Global.getAnalysisCache().getErrorLogger().reportSkippedAnalysis(method); }
private List<String> findFullyQualifiedSourceFileNames(IClassPathBuilder builder, IClassPath classPath) { List<ClassDescriptor> appClassList = builder.getAppClassList(); progress.startScanningClasses(appClassList.size()); List<String> fullyQualifiedSourceFileNameList = new LinkedList<>(); for (ClassDescriptor classDesc : appClassList) { try { String fullyQualifiedSourceFileName = findFullyQualifiedSourceFileName(classPath, classDesc); fullyQualifiedSourceFileNameList.add(fullyQualifiedSourceFileName); } catch (IOException e) { errorLogger.logError("Couldn't scan class " + classDesc.toDottedClassName(), e); } catch (CheckedAnalysisException e) { errorLogger.logError("Couldn't scan class " + classDesc.toDottedClassName(), e); } } progress.doneScanningClasses(); return fullyQualifiedSourceFileNameList; }
@Override public boolean matches(Type t) { if (!(t instanceof ReferenceType)) { return false; } IAnalysisCache analysisCache = Global.getAnalysisCache(); Subtypes2 subtypes2 = analysisCache.getDatabase(Subtypes2.class); try { return subtypes2.isSubtype((ReferenceType) t, supertype); } catch (ClassNotFoundException e) { analysisCache.getErrorLogger().reportMissingClass(e); return false; } }
private void initialize() { initialized = true; IAnalysisCache analysisCache = Global.getAnalysisCache(); Class<? extends Dataflow<Fact,AnalysisType>> cls = null; // First, try loading the dataflow class from the general findBugs code. try { Class<?> c = getClass().getClassLoader().loadClass(dataflowClassName); cls = asDataflowClass(c); } catch (ClassNotFoundException e) { assert true; } if (cls == null) { // Find the dataflow class from the plugin in which it was loaded DetectorFactoryCollection detectorFactoryCollection = analysisCache.getDatabase(DetectorFactoryCollection.class); for (Iterator<Plugin> i = detectorFactoryCollection.pluginIterator(); i.hasNext();) { Plugin plugin = i.next(); try { cls = asDataflowClass(plugin.getClassLoader().loadClass(dataflowClassName)); break; } catch (ClassNotFoundException e) { assert true; } } } if (cls == null) { analysisCache.getErrorLogger().logError("TestDataflowAnalysis: could not load class " + dataflowClassName); return; } dataflowClass = cls; }
/** * 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 classDescriptor * a ClassDescriptor naming a class type * @return an Obligation that is a supertype of the given type, or null if * there is no such Obligation */ public @CheckForNull Obligation getObligationByType(ClassDescriptor classDescriptor) { try { return getObligationByType(BCELUtil.getObjectTypeInstance(classDescriptor.toDottedClassName())); } catch (ClassNotFoundException e) { Global.getAnalysisCache().getErrorLogger().reportMissingClass(e); return null; } }
method = analysisCache.getMethodAnalysis(Method.class, descriptor); } catch (CheckedAnalysisException e1) { analysisCache.getErrorLogger().logError("Unable to get method for " + descriptor, e1); return null;
/** * Determine whether class named by given ClassDescriptor is an Obligation * type. * * @param classDescriptor * a class * @return true if the class is an Obligation type, false otherwise */ public boolean isObligationType(ClassDescriptor classDescriptor) { try { return getObligationByType(BCELUtil.getObjectTypeInstance(classDescriptor.toDottedClassName())) != null; } catch (ClassNotFoundException e) { Global.getAnalysisCache().getErrorLogger().reportMissingClass(e); return false; } }
/** * Attempt to parse data of given resource in order to divine the real name * of the class contained in the resource. * * @param entry * the resource */ private void parseClassName(ICodeBaseEntry entry) { DataInputStream in = null; try { InputStream resourceIn = entry.openResource(); if (resourceIn == null) { throw new NullPointerException("Got null resource"); } in = new DataInputStream(resourceIn); ClassParserInterface parser = new ClassParser(in, null, entry); ClassNameAndSuperclassInfo.Builder builder = new ClassNameAndSuperclassInfo.Builder(); parser.parse(builder); String trueResourceName = builder.build().getClassDescriptor().toResourceName(); if (!trueResourceName.equals(entry.getResourceName())) { entry.overrideResourceName(trueResourceName); } } catch (IOException e) { errorLogger.logError("Invalid class resource " + entry.getResourceName() + " in " + entry, e); } catch (InvalidClassFileFormatException e) { errorLogger.logError("Invalid class resource " + entry.getResourceName() + " in " + entry, e); } finally { IO.close(in); } }
/** * Get array of Obligation types corresponding to the parameters of the * given method. * * @param xmethod * a method * @return array of Obligation types for each of the method's parameters; a * null element means the corresponding parameter is not an * Obligation type */ public Obligation[] getParameterObligationTypes(XMethod xmethod) { Type[] paramTypes = Type.getArgumentTypes(xmethod.getSignature()); Obligation[] result = new Obligation[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) { if (!(paramTypes[i] instanceof ObjectType)) { continue; } try { result[i] = getObligationByType((ObjectType) paramTypes[i]); } catch (ClassNotFoundException e) { Global.getAnalysisCache().getErrorLogger().reportMissingClass(e); } } return result; }
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(); } }
errorLogger.reportMissingClass(e); throw new MissingClassException(e);
if (e instanceof FileNotFoundException) { if(item.isAppCodeBase()){ errorLogger.logError("File from project not found: " + item.getCodeBaseLocator(), e); } else { errorLogger.logError("File from auxiliary classpath not found: " + item.getCodeBaseLocator(), e); errorLogger.logError("Cannot open codebase " + item.getCodeBaseLocator(), e); errorLogger.logError("Cannot open codebase " + item.getCodeBaseLocator(), e);
logRecoverableException(classDescriptor, detector, e); } catch (MissingClassException e) { Global.getAnalysisCache().getErrorLogger().reportMissingClass(e.getClassDescriptor()); } catch (CheckedAnalysisException e) { logRecoverableException(classDescriptor, detector, e);
private DataflowResult<DataflowType> compute(TypeQualifierValue<?> typeQualifierValue) { DataflowResult<DataflowType> result = new DataflowResult<>(); try { IAnalysisCache analysisCache = Global.getAnalysisCache(); DepthFirstSearch dfs = analysisCache.getMethodAnalysis(DepthFirstSearch.class, methodDescriptor); XMethod xmethod = XFactory.createXMethod(methodDescriptor); CFG cfg = analysisCache.getMethodAnalysis(CFG.class, methodDescriptor); ValueNumberDataflow vnaDataflow = analysisCache.getMethodAnalysis(ValueNumberDataflow.class, methodDescriptor); ConstantPoolGen cpg = analysisCache.getClassAnalysis(ConstantPoolGen.class, methodDescriptor.getClassDescriptor()); DataflowType dataflow = getDataflow(dfs, xmethod, cfg, vnaDataflow, cpg, analysisCache, methodDescriptor, typeQualifierValue); result.dataflow = dataflow; if (TypeQualifierDatabase.USE_DATABASE) { try { populateDatabase(dataflow, vnaDataflow, xmethod, typeQualifierValue); } catch (DataflowAnalysisException e) { analysisCache.getErrorLogger().logError("Error populating type qualifier database", e); } } } catch (CheckedAnalysisException e) { result.checkedException = e; } catch (RuntimeException e) { result.runtimeException = e; } return result; }
@Override public void reportMissingClass(ClassNotFoundException ex) { Global.getAnalysisCache().getErrorLogger().reportMissingClass(ex); }