[Fb-contrib-commit] SF.net SVN: fb-contrib:[1131] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
From: <dbr...@us...> - 2009-03-01 09:32:11
|
Revision: 1131 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1131&view=rev Author: dbrosius Date: 2009-03-01 09:32:06 +0000 (Sun, 01 Mar 2009) Log Message: ----------- unfortunately have to load the class for which a method is called to get it's exceptions Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BogusExceptionDeclaration.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BogusExceptionDeclaration.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BogusExceptionDeclaration.java 2009-03-01 09:31:37 UTC (rev 1130) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BogusExceptionDeclaration.java 2009-03-01 09:32:06 UTC (rev 1131) @@ -13,7 +13,6 @@ import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.ba.ClassContext; -import edu.umd.cs.findbugs.ba.XMethod; /** * looks for constructors, private methods or static methods that declare that they @@ -22,8 +21,18 @@ */ public class BogusExceptionDeclaration extends BytecodeScanningDetector { private static JavaClass runtimeExceptionClass; + private static final Set<String> safeClasses = new HashSet<String>(); static { try { + safeClasses.add("java/lang/Object"); + safeClasses.add("java/lang/String"); + safeClasses.add("java/lang/Integer"); + safeClasses.add("java/lang/Long"); + safeClasses.add("java/lang/Float"); + safeClasses.add("java/lang/Double"); + safeClasses.add("java/lang/Short"); + safeClasses.add("java/lang/Boolean"); + runtimeExceptionClass = Repository.lookupClass("java/lang/RuntimeException"); } catch (ClassNotFoundException cnfe) { runtimeExceptionClass = null; @@ -103,10 +112,38 @@ || (seen == INVOKEINTERFACE) || (seen == INVOKESPECIAL) || (seen == INVOKESTATIC)) { - XMethod method = getXMethod(); - String[] thrownExceptions = method.getThrownExceptions(); - for (String thrownException : thrownExceptions) { - declaredCheckedExceptions.remove(thrownException.replaceAll("/", ".")); + String clsName = getClassConstantOperand(); + if (!safeClasses.contains(clsName)) { + try { + JavaClass cls = Repository.lookupClass(clsName); + Method[] methods = cls.getMethods(); + String methodName = getNameConstantOperand(); + String signature = getSigConstantOperand(); + boolean found = false; + for (Method m : methods) { + if (m.getName().equals(methodName) && m.getSignature().equals(signature)) { + ExceptionTable et = m.getExceptionTable(); + if (et != null) { + String[] thrownExceptions = et.getExceptionNames(); + for (String thrownException : thrownExceptions) { + declaredCheckedExceptions.remove(thrownException.replaceAll("/", ".")); + } + } else { + declaredCheckedExceptions.clear(); + } + found = true; + break; + } + } + + if (!found) { + declaredCheckedExceptions.clear(); + } + } + catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + declaredCheckedExceptions.clear(); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |