/** * Is this bug instance the result of an experimental detector? */ public boolean isExperimental() { BugPattern pattern = getBugPattern(); return pattern.isExperimental(); }
/** * Get the abbreviation of this bug instance's BugPattern. This is the same * abbreviation used by the BugCode which the BugPattern is a particular * species of. */ public String getAbbrev() { BugPattern pattern = getBugPattern(); return pattern.getAbbrev(); }
public String getCategoryAbbrev() { BugPattern bugPattern = getBugPattern(); return bugPattern.getCategoryAbbrev(); }
String getLongDescription() { return getBugPattern().getLongDescription().replaceAll("BUG_PATTERN", type); }
@Override public boolean match(BugInstance bugInstance) { if (DEBUG) { System.out.println("Checking " + bugInstance); System.out.println(" type:" + bugInstance.getType()); System.out.println(" against: " + bugPattern); } if (!(bugPattern == null || bugInstance.getType().startsWith(bugPattern) || bugInstance.getBugPattern().getCategory().equalsIgnoreCase(bugPattern) || bugInstance.getBugPattern() .getAbbrev().equalsIgnoreCase(bugPattern))) { return false; } if (DEBUG) { System.out.println(" pattern matches"); } return true; }
@Override public void reportBug(@Nonnull BugInstance bugInstance) { BugPattern bugPattern = bugInstance.getBugPattern(); String category = bugPattern.getCategory(); if (categorySet.contains(category)) { getDelegate().reportBug(bugInstance); } else { if (DEBUG) { System.out.println("CategoryFilteringBugReporter: filtered due to category " + category); } } } }
@Override public BugInstance findBug(String instanceHash, String bugType, int lineNumber) { for (BugInstance bug : bugSet) { if (bug.getInstanceHash().equals(instanceHash) && bug.getBugPattern().getType().equals(bugType) && bug.getPrimarySourceLineAnnotation().getStartLine() == lineNumber) { return bug; } } return null; }
public String getAbridgedMessage() { BugPattern bugPattern = getBugPattern(); String pattern = getLongDescription().replaceAll(" in \\{1\\}", ""); String shortPattern = bugPattern.getShortDescription(); try { FindBugsMessageFormat format = new FindBugsMessageFormat(pattern); return format.format(annotationList.toArray(new BugAnnotation[annotationList.size()]), getPrimaryClass(), true); } catch (RuntimeException e) { AnalysisContext.logError("Error generating bug msg ", e); return shortPattern + " [Error3 generating customized description]"; } }
public int getCWEid() { BugPattern pattern = getBugPattern(); int cweid = pattern.getCWEid(); if (cweid != 0) { return cweid; } BugCode bugCode = pattern.getBugCode(); return bugCode.getCWEid(); } public void writeXML(XMLOutput xmlOutput, BugCollection bugCollection, boolean addMessages) throws IOException {
public void setHistory(BugInstance from) { long first = from.getFirstVersion(); long last = from.getLastVersion(); if (first > 0 && last >= 0 && first > last) { throw new IllegalArgumentException("from has version range " + first + "..." + last + " in " + from.getBugPattern() + "\n" + from.getMessage()); } setFirstVersion(first); setLastVersion(last); this.removedByChangeOfPersistingClass = from.removedByChangeOfPersistingClass; this.introducedByChangeOfExistingClass = from.introducedByChangeOfExistingClass; }
private void foundInAutogeneratedMethod() { if (annotationList.size() != 2) { return; } priority+=2; setProperty("FOUND_IN_SYNTHETIC_METHOD", "true"); if (SystemProperties.ASSERTIONS_ENABLED && AnalysisContext.analyzingApplicationClass() && priority <= 3) { AnalysisContext.logError("Adding error " + getBugPattern().getType() + " to synthetic method " + getPrimaryMethod()); } }
@Override public boolean match(BugInstance bugInstance) { boolean result1 = codes.match(bugInstance.getAbbrev()); boolean result2 = patterns.match(bugInstance.getType()); boolean result3 = categories.match(bugInstance.getBugPattern().getCategory()); if (DEBUG) { System.out.println("Matching " + bugInstance.getAbbrev() + "/" + bugInstance.getType() + "/" + bugInstance.getBugPattern().getCategory() + " with " + this + ", result = " + result1 + "/" + result2 + "/" + result3); } return result1 || result2 || result3; }
/** * Format a string describing this bug instance. * * @return the description */ @Nonnull public String getMessageWithoutPrefix() { BugPattern bugPattern = getBugPattern(); String pattern, shortPattern; pattern = getLongDescription(); shortPattern = bugPattern.getShortDescription(); try { FindBugsMessageFormat format = new FindBugsMessageFormat(pattern); return format.format(annotationList.toArray(new BugAnnotation[annotationList.size()]), getPrimaryClass()); } catch (RuntimeException e) { AnalysisContext.logError("Error generating bug msg ", e); return shortPattern + " [Error generating customized description]"; } }
@Override public void reportBug(@Nonnull BugInstance bugInstance) { if (!category.equals(bugInstance.getBugPattern().getCategory())) { getDelegate().reportBug(bugInstance); return; } if (check.isEmpty()) { return; } ClassAnnotation c = bugInstance.getPrimaryClass(); @DottedClassName String packageName = c.getPackageName(); while (true) { if (check.contains(packageName)) { getDelegate().reportBug(bugInstance); return; } else if (dontCheck.contains(packageName)) { return; } int i = packageName.lastIndexOf('.'); if (i < 0) { return; } packageName = packageName.substring(0, i); } }
public static int findRank(BugInstance bug) { int patternRank = findRank(bug.getBugPattern(), bug.getDetectorFactory()); return adjustRank(patternRank, bug.getPriority()); }
/** * Get a string describing the bug priority and type. e.g. * "High Priority Correctness" * * @return a string describing the bug priority and type */ public String getPriorityTypeString() { String priorityString = getPriorityString(); BugPattern bugPattern = this.getBugPattern(); // then get the category and put everything together String categoryString = I18N.instance().getBugCategoryDescription(bugPattern.getCategory()); return priorityString + " Confidence " + categoryString; // TODO: internationalize the word "Confidence" }
/** * Format a string describing this bug instance. * * @return the description */ public String getMessage() { BugPattern bugPattern = getBugPattern(); String pattern = bugPattern.getAbbrev() + ": " + getLongDescription(); FindBugsMessageFormat format = new FindBugsMessageFormat(pattern); try { return format.format(annotationList.toArray(new BugAnnotation[annotationList.size()]), getPrimaryClass()); } catch (RuntimeException e) { AnalysisContext.logError("Error generating bug msg ", e); return bugPattern.getShortDescription() + " [Error generating customized description]"; } }
/** * Returns a printable String concatenating bug locations. */ private static String getBugsLocations(List<BugInstance> unexpectedBugs) { StringBuilder message = new StringBuilder(); for (BugInstance bugInstance : unexpectedBugs) { message.append("\n"); if (bugInstance.getBugPattern().getType().equals(FB_MISSING_EXPECTED_WARNING)) { message.append("missing "); } else { message.append("unexpected "); } StringAnnotation pattern = (StringAnnotation) bugInstance.getAnnotations().get(2); message.append(pattern.getValue()); message.append(" "); message.append(bugInstance.getPrimarySourceLineAnnotation()); } return message.toString(); }
/** * @param detectorName */ public void adjustForDetector(String detectorName) { DetectorFactory factory = DetectorFactoryCollection.instance().getFactoryByClassName(detectorName); detectorFactory = factory; if (factory != null) { this.priority += factory.getPriorityAdjustment(); boundPriority(); BugPattern bugPattern = getBugPattern(); if (SystemProperties.ASSERTIONS_ENABLED && !"EXPERIMENTAL".equals(bugPattern.getCategory()) && !factory.getReportedBugPatterns().contains(bugPattern)) { AnalysisContext.logError(factory.getShortName() + " doesn't note that it reports " + bugPattern + " in category " + bugPattern.getCategory()); } } }
private void writeBugCategories(XMLOutput xmlOutput) throws IOException { // Find bug categories reported Set<String> bugCatSet = new HashSet<>(); for (Iterator<BugInstance> i = iterator(); i.hasNext();) { BugInstance bugInstance = i.next(); BugPattern bugPattern = bugInstance.getBugPattern(); bugCatSet.add(bugPattern.getCategory()); } // Emit element describing each reported bug code for (String bugCat : bugCatSet) { String bugCatDescription = I18N.instance().getBugCategoryDescription(bugCat); if (bugCatDescription == null) { continue; } XMLAttributeList attributeList = new XMLAttributeList(); attributeList.addAttribute("category", bugCat); xmlOutput.openTag("BugCategory", attributeList); xmlOutput.openTag("Description"); xmlOutput.writeText(bugCatDescription); xmlOutput.closeTag("Description"); xmlOutput.closeTag("BugCategory"); } }