Java Code Examples for edu.umd.cs.findbugs.BugInstance#getPrimaryLocalVariableAnnotation()
The following examples show how to use
edu.umd.cs.findbugs.BugInstance#getPrimaryLocalVariableAnnotation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InfiniteLoop.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
void reportPossibleBug(BugInstance bug) { int catchSize = Util.getSizeOfSurroundingTryBlock(getConstantPool(), getCode(), "java/io/EOFException", getPC()); if (catchSize < Integer.MAX_VALUE) { bug.lowerPriorityALot(); } else { catchSize = Util.getSizeOfSurroundingTryBlock(getConstantPool(), getCode(), "java/lang/NoSuchElementException", getPC()); if (catchSize < Integer.MAX_VALUE) { bug.lowerPriorityALot(); } else { LocalVariableAnnotation lv = bug.getPrimaryLocalVariableAnnotation(); if (lv == null && "run".equals(getMethodName())) { bug.lowerPriority(); } } } bugReporter.reportBug(bug); }
Example 2
Source File: LocalMatcher.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public boolean match(BugInstance bugInstance) { LocalVariableAnnotation localAnnotation = bugInstance.getPrimaryLocalVariableAnnotation(); return localAnnotation != null && name.match(localAnnotation.getName()); }
Example 3
Source File: FindBugsExecutor.java From repositoryminer with Apache License 2.0 | 4 votes |
public Map<String, List<ReportedBug>> execute() throws IOException, InterruptedException, IllegalStateException { FindBugs2 findBugs = new FindBugs2(); Project project = getProject(); findBugs.setProject(project); XMLBugReporter reporter = new XMLBugReporter(project); reporter.setPriorityThreshold(bugPriority); reporter.setAddMessages(true); reporter.setUseLongBugCodes(true); findBugs.setBugReporter(reporter); UserPreferences userPrefs = UserPreferences.createDefaultUserPreferences(); userPrefs.setEffort(userPrefsEffort); findBugs.setUserPreferences(userPrefs); findBugs.setDetectorFactoryCollection(DetectorFactoryCollection.instance()); findBugs.setAnalysisFeatureSettings(effort); findBugs.finishSettings(); findBugs.execute(); Map<String, List<ReportedBug>> reportedBugs = new HashMap<String, List<ReportedBug>>(); for (BugInstance b : reporter.getBugCollection()) { String filename = b.getPrimarySourceLineAnnotation().getSourcePath(); if (!reportedBugs.containsKey(filename)) { reportedBugs.put(filename, new ArrayList<ReportedBug>()); } ReportedBug rb = new ReportedBug(b.getBugRank(), b.getBugRankCategory().toString(), b.getPriority(), b.getPriorityString(), b.getType(), b.getAbbrev(), b.getBugPattern().getDetailPlainText(), b.getBugPattern().getCategory(), b.getPrimaryClass().getClassName(), b.getAbridgedMessage(), b.getMessage()); if (b.getPrimaryMethod() != null) { String methodName = b.getPrimaryMethod().getFullMethod(b.getPrimaryClass()); rb.setMethod(methodName.substring(methodName.lastIndexOf(".") + 1)); } if (b.getPrimaryField() != null) { rb.setField(b.getPrimaryField().getFieldName()); } if (b.getPrimaryLocalVariableAnnotation() != null) { rb.setLocalVariable(b.getPrimaryLocalVariableAnnotation().getName()); } reportedBugs.get(filename).add(rb); } findBugs.dispose(); return reportedBugs; }