Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [649] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-09-14 04:57:19
|
Revision: 649 http://svn.sourceforge.net/fb-contrib/?rev=649&view=rev Author: dbrosius Date: 2006-09-13 21:57:15 -0700 (Wed, 13 Sep 2006) Log Message: ----------- add TODOs to AFBR Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2006-09-14 04:42:03 UTC (rev 648) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2006-09-14 04:57:15 UTC (rev 649) @@ -27,6 +27,8 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.FindBugsAnalysisFeatures; +import edu.umd.cs.findbugs.ba.AnalysisContext; import edu.umd.cs.findbugs.ba.ClassContext; /** @@ -54,6 +56,10 @@ */ @Override public void visitClassContext(ClassContext classContext) { + //TODO: Look at method calls in a finally block to see if they throw exceptions + // : and those exceptions are not caught in the finally block + // : Only do it if effort is on, ie: boolean fullAnalysis = AnalysisContext.currentAnalysisContext().getBoolProperty(FindBugsAnalysisFeatures.INTERPROCEDURAL_ANALYSIS_OF_REFERENCED_CLASSES); + try { int majorVersion = classContext.getJavaClass().getMajor(); if (majorVersion >= MAJOR_1_4) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-30 08:35:28
|
Revision: 806 http://svn.sourceforge.net/fb-contrib/?rev=806&view=rev Author: dbrosius Date: 2007-01-30 00:35:27 -0800 (Tue, 30 Jan 2007) Log Message: ----------- address bug 1555116 report methods called in finally blocks that may throw exceptions, but that are not handled in try/catch blocks inside the finally block. In fact, it only looks for a try/catch block regardless of catch type, so a few false positives will fall thru, but doing this would be prohibitive. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2007-01-30 06:47:15 UTC (rev 805) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2007-01-30 08:35:27 UTC (rev 806) @@ -21,8 +21,12 @@ import java.util.ArrayList; import java.util.List; +import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.CodeException; +import org.apache.bcel.classfile.ExceptionTable; +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; @@ -150,10 +154,77 @@ .addMethod(this) .addSourceLine(this)); fbInfo.remove(0); + } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE) || (seen == INVOKESPECIAL) || (seen == INVOKESTATIC)) { + try { + JavaClass cls = Repository.lookupClass(getClassConstantOperand()); + Method m = findMethod(cls, getNameConstantOperand(), getSigConstantOperand()); + if (m != null) { + ExceptionTable et = m.getExceptionTable(); + if ((et != null) && (et.getLength() > 0)) { + if (!catchBlockInFinally(fbi)) { + bugReporter.reportBug(new BugInstance( this, "AFBR_ABNORMAL_FINALLY_BLOCK_RETURN", LOW_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + fbInfo.remove(0); + } + } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } } } /** + * finds the method in specified class by name and signature + * + * @param cls the class to look the method in + * @param name the name of the method to look for + * @param sig the signature of the method to look for + * + * @return the Method object for the specified information + */ + private Method findMethod(JavaClass cls, String name, String sig) { + Method[] methods = cls.getMethods(); + for (Method m : methods) { + if (m.getName().equals(name) && m.getSignature().equals(sig)) { + return m; + } + } + + return null; + } + + /** + * looks to see if any try/catch block exists inside this finally block, that + * wrap the current pc. This is a lax check as the try catch block may not + * catch exceptions that are thrown, but doing so would be prohibitively slow. + * But it should catch some problems. + * + * @param fbInfo the finally block the pc is currently in + * + * @return if all exceptions are caught inside this finally block + */ + private boolean catchBlockInFinally(FinallyBlockInfo fbInfo) { + + CodeException[] catchExceptions = getCode().getExceptionTable(); + if ((catchExceptions == null) || (catchExceptions.length == 0)) + return false; + + int pc = getPC(); + for (CodeException ex : catchExceptions) { + if ((ex.getStartPC() <= pc) && (ex.getEndPC() >= pc)) { + if (ex.getStartPC() >= fbInfo.startPC) { + return true; + } + } + } + + return false; + } + + /** * holds the finally block information for a particular method. */ public static class FinallyBlockInfo This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |