use of edu.umd.cs.findbugs.StringAnnotation in project fb-contrib by mebigfatguy.
the class RuntimeExceptionDeclared method visitMethod.
/**
* overrides the visitor to find declared runtime exceptions
*
* @param obj
* the method object of the currently parsed method
*/
@Override
public void visitMethod(final Method obj) {
if (obj.isSynthetic()) {
return;
}
ExceptionTable et = obj.getExceptionTable();
if (et != null) {
String[] exNames = et.getExceptionNames();
Set<String> methodRTExceptions = new HashSet<>(6);
int priority = LOW_PRIORITY;
boolean foundRuntime = false;
for (String ex : exNames) {
boolean isRuntime = false;
if (runtimeExceptions.contains(ex)) {
isRuntime = true;
} else {
try {
JavaClass exClass = Repository.lookupClass(ex);
if (exClass.instanceOf(runtimeExceptionClass)) {
runtimeExceptions.add(ex);
if (ex.startsWith("java.lang.")) {
priority = NORMAL_PRIORITY;
}
isRuntime = true;
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
if (isRuntime) {
foundRuntime = true;
methodRTExceptions.add(ex);
}
}
if (foundRuntime) {
BugInstance bug = new BugInstance(this, BugType.DRE_DECLARED_RUNTIME_EXCEPTION.name(), priority).addClass(this).addMethod(this);
for (String ex : methodRTExceptions) {
bug.add(new StringAnnotation(ex));
}
bugReporter.reportBug(bug);
}
}
}
Aggregations