Java Code Examples for edu.umd.cs.findbugs.BugInstance#getPriority()
The following examples show how to use
edu.umd.cs.findbugs.BugInstance#getPriority() .
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: ProjectFilterSettings.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
/** * Return whether or not a warning should be displayed, according to the * project filter settings. * * @param bugInstance * the warning * @return true if the warning should be displayed, false if not */ public boolean displayWarning(BugInstance bugInstance) { int priority = bugInstance.getPriority(); if (priority > getMinPriorityAsInt()) { return false; } int rank = bugInstance.getBugRank(); if (rank > getMinRank()) { return false; } BugPattern bugPattern = bugInstance.getBugPattern(); // HACK: it is conceivable that the detector plugin which generated // this warning is not available any more, in which case we can't // find out the category. Let the warning be visible in this case. if (!containsCategory(bugPattern.getCategory())) { return false; } if (!displayFalseWarnings) { boolean isFalseWarning = !Boolean.valueOf(bugInstance.getProperty(BugProperty.IS_BUG, "true")).booleanValue(); if (isFalseWarning) { return false; } } return true; }
Example 2
Source File: FindBugsParser.java From analysis-model with MIT License | 5 votes |
/** * Maps the FindBugs library priority to plug-in priority enumeration. * * @param warning * the FindBugs warning * * @return mapped priority enumeration */ private Severity getPriorityByPriority(final BugInstance warning) { switch (warning.getPriority()) { case 1: return Severity.WARNING_HIGH; case 2: return Severity.WARNING_NORMAL; default: return Severity.WARNING_LOW; } }
Example 3
Source File: FindMaskedFields.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void report() { UnreadFieldsData unreadFields = AnalysisContext.currentAnalysisContext().getUnreadFieldsData(); for (RememberedBug rb : rememberedBugs) { BugInstance bug = rb.bug; int score1 = 0; int score2 = 0; int priority = bug.getPriority(); if (unreadFields.classesScanned.contains(rb.maskedField.getClassName())) { if (unreadFields.getReadFields().contains(rb.maskedField)) { score1++; } if (unreadFields.getWrittenFields().contains(rb.maskedField)) { score1++; } if (unreadFields.isWrittenOutsideOfInitialization(rb.maskedField)) { score1++; } } else { score1 += 2; } if (unreadFields.getReadFields().contains(rb.maskingField)) { score2++; } if (unreadFields.getWrittenFields().contains(rb.maskingField)) { score2++; } if (unreadFields.isWrittenOutsideOfInitialization(rb.maskingField)) { score2++; } int score = score1 + score2; if (score1 == 0 || score2 == 0) { bug.setPriority(priority + 1); } else if (score >= 5) { bug.setPriority(priority - 1); } else if (score < 3) { bug.setPriority(priority + 1); } bugReporter.reportBug(bug); } }
Example 4
Source File: CheckExpectedWarnings.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
private static Collection<SourceLineAnnotation> countWarnings(Collection<BugInstance> warnings, @CheckForNull String bugCode, int desiredPriority, int rank) { Collection<SourceLineAnnotation> matching = new HashSet<>(); DetectorFactoryCollection i18n = DetectorFactoryCollection.instance(); boolean matchPattern = false; try { i18n.getBugCode(bugCode); } catch (IllegalArgumentException e) { matchPattern = true; } if (warnings != null) { for (BugInstance warning : warnings) { if (warning.getPriority() > desiredPriority) { continue; } if (warning.getBugRank() > rank) { continue; } if (bugCode == null) { matching.add(warning.getPrimarySourceLineAnnotation()); matching.addAll(warning.getAnotherInstanceSourceLineAnnotations()); continue; } BugPattern pattern = warning.getBugPattern(); String match; if (matchPattern) { match = pattern.getType(); } else { match = pattern.getAbbrev(); } if (match.equals(bugCode)) { matching.add(warning.getPrimarySourceLineAnnotation()); matching.addAll(warning.getAnotherInstanceSourceLineAnnotations()); } } } return matching; }
Example 5
Source File: ConfidenceMatcher.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public boolean match(BugInstance bugInstance) { return bugInstance.getPriority() == confidence; }
Example 6
Source File: PriorityMatcher.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public boolean match(BugInstance bugInstance) { return bugInstance.getPriority() == priority; }
Example 7
Source File: ViewFilter.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public boolean show(MainFrame mf, BugInstance b) { return b.getPriority() <= maxPriority; }
Example 8
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; }