"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/java/edu/umd/cs/findbugs/detect/CheckExpectedWarnings.java" between
findbugs-3.0.0-source.zip and findbugs-3.0.1-source.zip

About: FindBugs uses static analysis to look for bugs in Java code. Source.

CheckExpectedWarnings.java  (findbugs-3.0.0-source):CheckExpectedWarnings.java  (findbugs-3.0.1-source)
skipping to change at line 184 skipping to change at line 184
} }
} }
XClass xclass = Global.getAnalysisCache().getClassAnalysis(XClass.class, classDescriptor); XClass xclass = Global.getAnalysisCache().getClassAnalysis(XClass.class, classDescriptor);
List<? extends XMethod> methods = xclass.getXMethods(); List<? extends XMethod> methods = xclass.getXMethods();
if (DEBUG) { if (DEBUG) {
System.out.println("CEW: checking " + xclass.toString()); System.out.println("CEW: checking " + xclass.toString());
} }
if (xclass.isSynthetic()) {
if (DEBUG) {
System.out.println("Skipping synthetic classxclass " + xclass.to
String());
}
return;
}
check(xclass, expectWarning, true, HIGH_PRIORITY); check(xclass, expectWarning, true, HIGH_PRIORITY);
check(xclass, desireWarning, true, NORMAL_PRIORITY); check(xclass, desireWarning, true, NORMAL_PRIORITY);
check(xclass, noWarning, false, HIGH_PRIORITY); check(xclass, noWarning, false, HIGH_PRIORITY);
check(xclass, desireNoWarning, false, NORMAL_PRIORITY); check(xclass, desireNoWarning, false, NORMAL_PRIORITY);
for (XMethod xmethod : methods) { for (XMethod xmethod : methods) {
if (DEBUG) { if (DEBUG) {
System.out.println("CEW: checking " + xmethod.toString()); System.out.println("CEW: checking " + xmethod.toString());
} }
if (xmethod.isSynthetic()) {
if (DEBUG) {
System.out.println("Skipping synthetic method " + xmethod.to
String());
}
continue;
}
check(xmethod, expectWarning, true, HIGH_PRIORITY); check(xmethod, expectWarning, true, HIGH_PRIORITY);
check(xmethod, desireWarning, true, NORMAL_PRIORITY); check(xmethod, desireWarning, true, NORMAL_PRIORITY);
check(xmethod, noWarning, false, HIGH_PRIORITY); check(xmethod, noWarning, false, HIGH_PRIORITY);
check(xmethod, desireNoWarning, false, NORMAL_PRIORITY); check(xmethod, desireNoWarning, false, NORMAL_PRIORITY);
} }
for (XField xfield : xclass.getXFields()) { for (XField xfield : xclass.getXFields()) {
if (DEBUG) { if (DEBUG) {
System.out.println("CEW: checking " + xfield.toString()); System.out.println("CEW: checking " + xfield.toString());
} }
if (xfield.isSynthetic()) {
if (DEBUG) {
System.out.println("Skipping synthetic field " + xfield.toSt
ring());
}
continue;
}
check(xfield, expectWarning, true, HIGH_PRIORITY); check(xfield, expectWarning, true, HIGH_PRIORITY);
check(xfield, desireWarning, true, NORMAL_PRIORITY); check(xfield, desireWarning, true, NORMAL_PRIORITY);
check(xfield, noWarning, false, HIGH_PRIORITY); check(xfield, noWarning, false, HIGH_PRIORITY);
check(xfield, desireNoWarning, false, NORMAL_PRIORITY); check(xfield, desireNoWarning, false, NORMAL_PRIORITY);
} }
} }
private void check(XClass xclass, ClassDescriptor annotation, boolean expect Warnings, int priority) { private void check(XClass xclass, ClassDescriptor annotation, boolean expect Warnings, int priority) {
AnnotationValue expect = xclass.getAnnotation(annotation); AnnotationValue expect = xclass.getAnnotation(annotation);
skipping to change at line 303 skipping to change at line 321
} }
} }
public void checkAnnotation(@CheckForNull String bugCode, Collection<BugInst ance> warnings, boolean expectWarnings, int priority, public void checkAnnotation(@CheckForNull String bugCode, Collection<BugInst ance> warnings, boolean expectWarnings, int priority,
Integer rank, Integer num, Object methodDescriptor, int minPriority, ClassDescriptor cd) { Integer rank, Integer num, Object methodDescriptor, int minPriority, ClassDescriptor cd) {
String bugCodeMessage = bugCode != null ? bugCode : "any bug"; String bugCodeMessage = bugCode != null ? bugCode : "any bug";
Collection<SourceLineAnnotation> bugs = countWarnings(warnings, bugCode, minPriority, Collection<SourceLineAnnotation> bugs = countWarnings(warnings, bugCode, minPriority,
rank); rank);
if (expectWarnings && bugs.size() < num) { if (expectWarnings && bugs.size() < num) {
if (DetectorFactoryCollection.instance().isDisabledByDefault(bugCode
)) {
return;
}
BugInstance bug = makeWarning("FB_MISSING_EXPECTED_WARNING", methodD escriptor, priority, cd).addString(bugCodeMessage); BugInstance bug = makeWarning("FB_MISSING_EXPECTED_WARNING", methodD escriptor, priority, cd).addString(bugCodeMessage);
if (!bugs.isEmpty()) { if (!bugs.isEmpty()) {
bug.addString(String.format("Expected %d bugs, saw %d", num, bug s.size())); bug.addString(String.format("Expected %d bugs, saw %d", num, bug s.size()));
} }
reporter.reportBug(bug); reporter.reportBug(bug);
} else if (bugs.size() > num) { } else if (bugs.size() > num) {
// More bugs than expected // More bugs than expected
BugInstance bug = makeWarning("FB_UNEXPECTED_WARNING", methodDescrip tor, priority, cd).addString(bugCodeMessage); BugInstance bug = makeWarning("FB_UNEXPECTED_WARNING", methodDescrip tor, priority, cd).addString(bugCodeMessage);
if (!expectWarnings) { if (!expectWarnings) {
// Wanted no more than this many warnings // Wanted no more than this many warnings
skipping to change at line 345 skipping to change at line 366
if (DEBUG) { if (DEBUG) {
System.out.println("Reporting " + bug); System.out.println("Reporting " + bug);
} }
return bug; return bug;
} }
private static Collection<SourceLineAnnotation> countWarnings( Collection<Bu gInstance> warnings, private static Collection<SourceLineAnnotation> countWarnings( Collection<Bu gInstance> warnings,
@CheckForNull String bugCode, @CheckForNull String bugCode,
int desiredPriority, int rank) { int desiredPriority, int rank) {
Collection<SourceLineAnnotation> matching = new HashSet<SourceLineAnnota tion>(); Collection<SourceLineAnnotation> matching = new HashSet<SourceLineAnnota tion>();
DetectorFactoryCollection i18n = DetectorFactoryCollection.instance(); DetectorFactoryCollection i18n = DetectorFactoryCollection.instance();
boolean matchPattern = false; boolean matchPattern = false;
try { try {
i18n.getBugCode(bugCode); i18n.getBugCode(bugCode);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
matchPattern = true; matchPattern = true;
} }
if (warnings != null) { if (warnings != null) {
skipping to change at line 392 skipping to change at line 414
} }
@Override @Override
public void finishPass() { public void finishPass() {
HashSet<BugPattern> claimedReported = new HashSet<BugPattern>(); HashSet<BugPattern> claimedReported = new HashSet<BugPattern>();
for (DetectorFactory d : DetectorFactoryCollection.instance().getFactori es()) { for (DetectorFactory d : DetectorFactoryCollection.instance().getFactori es()) {
claimedReported.addAll(d.getReportedBugPatterns()); claimedReported.addAll(d.getReportedBugPatterns());
} }
for (BugPattern b : DetectorFactoryCollection.instance().getBugPatterns( )) { for (BugPattern b : DetectorFactoryCollection.instance().getBugPatterns( )) {
String category = b.getCategory(); String category = b.getCategory();
if (!b.isDeprecated() && !category.equals("EXPERIMENTAL") && !claime dReported.contains(b)) { if (!b.isDeprecated() && !"EXPERIMENTAL".equals(category) && !claime dReported.contains(b)) {
AnalysisContext.logError("No detector claims " + b.getType()); AnalysisContext.logError("No detector claims " + b.getType());
} }
} }
} }
@Override @Override
public String getDetectorClassName() { public String getDetectorClassName() {
return CheckExpectedWarnings.class.getName(); return CheckExpectedWarnings.class.getName();
} }
 End of changes. 6 change blocks. 
1 lines changed or deleted 27 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS