⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 findbugs.java

📁 A static analysis tool to find bugs in Java programs
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
			new AnalysisFeatureSetting(FindBugsAnalysisFeatures.INTERPROCEDURAL_ANALYSIS, false),			new AnalysisFeatureSetting(FindBugsAnalysisFeatures.INTERPROCEDURAL_ANALYSIS_OF_REFERENCED_CLASSES, false),	};	public static final AnalysisFeatureSetting[] LESS_EFFORT = new AnalysisFeatureSetting[]{		new AnalysisFeatureSetting(AnalysisFeatures.CONSERVE_SPACE, false),		new AnalysisFeatureSetting(AnalysisFeatures.ACCURATE_EXCEPTIONS, true),		new AnalysisFeatureSetting(AnalysisFeatures.MODEL_INSTANCEOF, true),		new AnalysisFeatureSetting(AnalysisFeatures.SKIP_HUGE_METHODS, true),		new AnalysisFeatureSetting(AnalysisFeatures.INTERATIVE_OPCODE_STACK_ANALYSIS, true),		new AnalysisFeatureSetting(AnalysisFeatures.TRACK_GUARANTEED_VALUE_DEREFS_IN_NULL_POINTER_ANALYSIS, false),		new AnalysisFeatureSetting(AnalysisFeatures.TRACK_VALUE_NUMBERS_IN_NULL_POINTER_ANALYSIS, false),		new AnalysisFeatureSetting(FindBugsAnalysisFeatures.INTERPROCEDURAL_ANALYSIS, false),		new AnalysisFeatureSetting(FindBugsAnalysisFeatures.INTERPROCEDURAL_ANALYSIS_OF_REFERENCED_CLASSES, false),};	public static final AnalysisFeatureSetting[] DEFAULT_EFFORT = new AnalysisFeatureSetting[]{			new AnalysisFeatureSetting(AnalysisFeatures.CONSERVE_SPACE, false),			new AnalysisFeatureSetting(AnalysisFeatures.ACCURATE_EXCEPTIONS, true),			new AnalysisFeatureSetting(AnalysisFeatures.MODEL_INSTANCEOF, true),			new AnalysisFeatureSetting(AnalysisFeatures.SKIP_HUGE_METHODS, true),			new AnalysisFeatureSetting(AnalysisFeatures.INTERATIVE_OPCODE_STACK_ANALYSIS, true),			new AnalysisFeatureSetting(AnalysisFeatures.TRACK_GUARANTEED_VALUE_DEREFS_IN_NULL_POINTER_ANALYSIS, true),			new AnalysisFeatureSetting(AnalysisFeatures.TRACK_VALUE_NUMBERS_IN_NULL_POINTER_ANALYSIS, true),			new AnalysisFeatureSetting(FindBugsAnalysisFeatures.INTERPROCEDURAL_ANALYSIS, true),			new AnalysisFeatureSetting(FindBugsAnalysisFeatures.INTERPROCEDURAL_ANALYSIS_OF_REFERENCED_CLASSES, false),	};	public static final AnalysisFeatureSetting[] MORE_EFFORT = new AnalysisFeatureSetting[]{		new AnalysisFeatureSetting(AnalysisFeatures.CONSERVE_SPACE, false),		new AnalysisFeatureSetting(AnalysisFeatures.ACCURATE_EXCEPTIONS, true),		new AnalysisFeatureSetting(AnalysisFeatures.MODEL_INSTANCEOF, true),		new AnalysisFeatureSetting(AnalysisFeatures.SKIP_HUGE_METHODS, true),		new AnalysisFeatureSetting(AnalysisFeatures.INTERATIVE_OPCODE_STACK_ANALYSIS, true),		new AnalysisFeatureSetting(AnalysisFeatures.TRACK_GUARANTEED_VALUE_DEREFS_IN_NULL_POINTER_ANALYSIS, true),		new AnalysisFeatureSetting(AnalysisFeatures.TRACK_VALUE_NUMBERS_IN_NULL_POINTER_ANALYSIS, true),		new AnalysisFeatureSetting(FindBugsAnalysisFeatures.INTERPROCEDURAL_ANALYSIS, true),		new AnalysisFeatureSetting(FindBugsAnalysisFeatures.INTERPROCEDURAL_ANALYSIS_OF_REFERENCED_CLASSES, false),};	public static final AnalysisFeatureSetting[] MAX_EFFORT = new AnalysisFeatureSetting[]{			new AnalysisFeatureSetting(AnalysisFeatures.CONSERVE_SPACE, false),			new AnalysisFeatureSetting(AnalysisFeatures.ACCURATE_EXCEPTIONS, true),			new AnalysisFeatureSetting(AnalysisFeatures.MODEL_INSTANCEOF, true),			new AnalysisFeatureSetting(AnalysisFeatures.SKIP_HUGE_METHODS, false),			new AnalysisFeatureSetting(AnalysisFeatures.INTERATIVE_OPCODE_STACK_ANALYSIS, true),			new AnalysisFeatureSetting(AnalysisFeatures.TRACK_GUARANTEED_VALUE_DEREFS_IN_NULL_POINTER_ANALYSIS, true),			new AnalysisFeatureSetting(AnalysisFeatures.TRACK_VALUE_NUMBERS_IN_NULL_POINTER_ANALYSIS, true),			new AnalysisFeatureSetting(FindBugsAnalysisFeatures.INTERPROCEDURAL_ANALYSIS, true),			new AnalysisFeatureSetting(FindBugsAnalysisFeatures.INTERPROCEDURAL_ANALYSIS_OF_REFERENCED_CLASSES, true),	};	public static final boolean DEBUG = SystemProperties.getBoolean("findbugs.debug");	public static final boolean TIMEDEBUG = SystemProperties.getBoolean("findbugs.time");	public static final int TIMEQUANTUM = SystemProperties.getInteger("findbugs.time.quantum", 1000);	/**	 * FindBugs home directory.	 */	private static String home;	/**	 * Known URL protocols.	 * Filename URLs that do not have an explicit protocol are	 * assumed to be files.	 */	static public final Set<String> knownURLProtocolSet = new HashSet<String>();	static {		knownURLProtocolSet.add("file");		knownURLProtocolSet.add("http");		knownURLProtocolSet.add("https");		knownURLProtocolSet.add("jar");	}	private ErrorCountingBugReporter bugReporter;	private boolean relaxedReportingMode;	private Project project;	private DetectorFactoryCollection detectorFactoryCollection;	private UserPreferences userPreferences;	private List<IClassObserver> classObserverList;	private ExecutionPlan executionPlan;	private FindBugsProgress progressCallback;	private IClassScreener classScreener;	private AnalysisContext analysisContext;	private String currentClass;	private Map<String,Long> detectorTimings;	private boolean useTrainingInput;	private boolean emitTrainingOutput;	private String trainingInputDir;	private String trainingOutputDir;	private AnalysisFeatureSetting[] settingList = DEFAULT_EFFORT;	private String releaseName;	private String projectName;	private int passCount;	private String sourceInfoFile;	/* ----------------------------------------------------------------------	 * Public methods	 * ---------------------------------------------------------------------- */	/**	 * Constructor.	 * The setBugReporter() and setProject() methods must be called	 * before this object is used.	 */	public FindBugs() {		this.relaxedReportingMode = false;		this.classObserverList = new LinkedList<IClassObserver>();		// Create a no-op progress callback.		this.progressCallback = new NoOpFindBugsProgress();		// Class screener		this.classScreener = new ClassScreener();	}	/**	 * Constructor.	 *	 * @param bugReporter the BugReporter object that will be used to report	 *                    BugInstance objects, analysis errors, class to source mapping, etc.	 * @param project     the Project indicating which files to analyze and	 *                    the auxiliary classpath to use; note that the FindBugs	 *                    object will create a private copy of the Project object	 */	public FindBugs(BugReporter bugReporter, Project project) {		this();		if (bugReporter == null)			throw new IllegalArgumentException("null bugReporter");		if (project == null)			throw new IllegalArgumentException("null project");		setBugReporter(bugReporter);		setProject(project);	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#setDetectorFactoryCollection(edu.umd.cs.findbugs.DetectorFactoryCollection)	 */	public void setDetectorFactoryCollection(DetectorFactoryCollection detectorFactoryCollection) {		this.detectorFactoryCollection = detectorFactoryCollection;	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#getBugReporter()	 */	public BugReporter getBugReporter() {		return bugReporter;	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#setBugReporter(edu.umd.cs.findbugs.BugReporter)	 */	public void setBugReporter(BugReporter bugReporter) {		this.bugReporter = new ErrorCountingBugReporter(bugReporter);		addClassObserver(bugReporter);	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#setProject(edu.umd.cs.findbugs.Project)	 */	public void setProject(Project project) {		this.project = project.duplicate();	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#getProject()	 */	public Project getProject() {		return project;	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#setProgressCallback(edu.umd.cs.findbugs.FindBugsProgress)	 */	public void setProgressCallback(FindBugsProgress progressCallback) {		this.progressCallback = progressCallback;	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#addFilter(java.lang.String, boolean)	 */	public void addFilter(String filterFileName, boolean include) throws IOException, FilterException {		configureFilter(bugReporter, filterFileName, include);	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#setUserPreferences(edu.umd.cs.findbugs.config.UserPreferences)	 */	public void setUserPreferences(UserPreferences userPreferences) {		this.userPreferences = userPreferences;	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#addClassObserver(edu.umd.cs.findbugs.classfile.IClassObserver)	 */	public void addClassObserver(IClassObserver classObserver) {		classObserverList.add(classObserver);	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#setClassScreener(edu.umd.cs.findbugs.ClassScreener)	 */	public void setClassScreener(IClassScreener classScreener) {		this.classScreener = classScreener;	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#setRelaxedReportingMode(boolean)	 */	public void setRelaxedReportingMode(boolean relaxedReportingMode) {		this.relaxedReportingMode = relaxedReportingMode;	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#enableTrainingOutput(java.lang.String)	 */	public void enableTrainingOutput(String trainingOutputDir) {		this.emitTrainingOutput = true;		this.trainingOutputDir = trainingOutputDir;	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#enableTrainingInput(java.lang.String)	 */	public void enableTrainingInput(String trainingInputDir) {		this.useTrainingInput = true;		this.trainingInputDir = trainingInputDir;	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#setAnalysisFeatureSettings(edu.umd.cs.findbugs.config.AnalysisFeatureSetting[])	 */	public void setAnalysisFeatureSettings(AnalysisFeatureSetting[] settingList) {		if (settingList != null)			this.settingList  = settingList;	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#getReleaseName()	 */	public String getReleaseName() {		return releaseName;	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#setReleaseName(java.lang.String)	 */	public void setReleaseName(String releaseName) {		this.releaseName = releaseName;	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#setSourceInfoFile(java.lang.String)	 */	public void setSourceInfoFile(String sourceInfoFile) {		this.sourceInfoFile = sourceInfoFile;	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#execute()	 */	public void execute() throws java.io.IOException, InterruptedException {		// Configure the analysis context		analysisContext = AnalysisContext.create(bugReporter);		// We still need to call analysisContext.initDatabases(), but not until after we have set up the repository.		analysisContext.setSourcePath(project.getSourceDirList());		if (sourceInfoFile != null) {			analysisContext.getSourceInfoMap().read(new FileInputStream(sourceInfoFile));		}		// Enable/disable relaxed reporting mode		FindBugsAnalysisFeatures.setRelaxedMode(relaxedReportingMode);		// Enable input/output of interprocedural property databases		configureTrainingDatabases(this);		// Configure analysis features		configureAnalysisFeatures();		// Set the release name and timestamp(s) in the BugCollection (if we are generating one).		configureBugCollection(this);		// Create execution plan		try {			createExecutionPlan();		} catch (OrderingConstraintException e) {			IOException ioe = new IOException("Invalid detector ordering constraints");			ioe.initCause(e);			throw ioe;		}		// Clear the repository of classes		analysisContext.clearRepository();		// Get list of files to analyze.		LinkedList<ArchiveWorkListItem> archiveWorkList = new LinkedList<ArchiveWorkListItem>();		for (String fileName : project.getFileList()) {			archiveWorkList.add(new ArchiveWorkListItem(fileName, true));		}		// Report how many archives/directories/files will be analyzed,		// for progress dialog in GUI		progressCallback.reportNumberOfArchives(archiveWorkList.size());		// Keep track of the names of all classes to be analyzed		List<String> repositoryClassList = new LinkedList<String>();		// set the initial repository classpath.		setRepositoryClassPath();		// Record additional entries that should be added to		// the aux classpath.  These occur when one or more classes		// in a directory or archive are skipped, to ensure that		// the skipped classes can still be referenced.		List<String> additionalAuxClasspathEntryList = new LinkedList<String>();		// Add all classes in analyzed archives/directories/files		while (!archiveWorkList.isEmpty()) {			ArchiveWorkListItem item = archiveWorkList.removeFirst();			scanArchiveOrDirectory(item, archiveWorkList, repositoryClassList,				additionalAuxClasspathEntryList);		}		// Add "extra" aux classpath entries needed to ensure that		// skipped classes can be referenced.		addCollectionToClasspath(additionalAuxClasspathEntryList);		// finish up initializing analysisContext		analysisContext.initDatabases();		// Examine all classes for bugs.		// Don't examine the same class more than once.		// (The user might specify two jar files that contain		// the same class.)		if (DEBUG)			detectorTimings = new HashMap<String,Long>();		Iterator<AnalysisPass> i = executionPlan.passIterator();		if (i.hasNext()) {		AnalysisPass firstPass = i.next();		// Do this to force referenced classes to be loaded		Set<JavaClass> allReferencedClasses = analysisContext.getSubtypes().getAllClasses();		ArrayList<String> listOfReferencedClasses = new ArrayList<String>(allReferencedClasses.size());		for(JavaClass c : allReferencedClasses)			listOfReferencedClasses.add(c.getClassName());		executeAnalysisPass(firstPass, listOfReferencedClasses);		analysisContext.clearClassContextCache();		}		else if (DEBUG) System.err.println("execution plan has no passes");		// Execute each subsequent analysis pass in the execution plan		while (i.hasNext()) {			AnalysisPass analysisPass = i.next();			executeAnalysisPass(analysisPass, repositoryClassList);			if (false) 				System.out.println("Class content stats: " + analysisContext.getClassContextStats());			// Clear the ClassContext cache.			// It may contain data that should be recomputed on the next pass.			analysisContext.clearClassContextCache();		}		// Flush any queued bug reports		bugReporter.finish();		// Flush any queued error reports		bugReporter.reportQueuedErrors();		// Free up memory for reports		analysisContext.clearRepository();		if (false)		System.out.println(analysisContext.getClassContextStats());	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#getCurrentClass()	 */	public String getCurrentClass() {		return currentClass;	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#getBugCount()	 */	public int getBugCount() {		return bugReporter.getBugCount();	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#getErrorCount()	 */	public int getErrorCount() {		return bugReporter.getErrorCount();	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.IFindBugsEngine#getMissingClassCount()	 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -