[Fb-contrib-commit] SF.net SVN: fb-contrib: [802] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2007-01-28 21:47:44
|
Revision: 802 http://svn.sourceforge.net/fb-contrib/?rev=802&view=rev Author: dbrosius Date: 2007-01-28 13:47:38 -0800 (Sun, 28 Jan 2007) Log Message: ----------- remove a big false positive area where the implementation of a interface method declares that it DOES NOT throw an exception defined by the interface, and the method that uses this method doesn't handle that type of exception. Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/samples/OCP_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-01-28 21:08:03 UTC (rev 801) +++ trunk/fb-contrib/etc/findbugs.xml 2007-01-28 21:47:38 UTC (rev 802) @@ -41,7 +41,7 @@ reports="CC_CYCLOMATIC_COMPLEXITY" /> <Detector class="com.mebigfatguy.fbcontrib.detect.OverlyConcreteParameter" - speed="moderate" + speed="slow" reports="OCP_OVERLY_CONCRETE_PARAMETER" /> <Detector class="com.mebigfatguy.fbcontrib.detect.ListIndexedIterating" Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-01-28 21:08:03 UTC (rev 801) +++ trunk/fb-contrib/etc/messages.xml 2007-01-28 21:47:38 UTC (rev 802) @@ -66,7 +66,7 @@ <p> Looks for parameters that are defined by classes, but only use methods defined by an implemented interface or super class. Relying on concrete classes in public signatures causes cohesion, and makes low impact changes more difficult.</p> - <p>It is a moderately fast detector</p> + <p>It is a slow detector</p> ]]> </Details> </Detector> Modified: trunk/fb-contrib/samples/OCP_Sample.java =================================================================== --- trunk/fb-contrib/samples/OCP_Sample.java 2007-01-28 21:08:03 UTC (rev 801) +++ trunk/fb-contrib/samples/OCP_Sample.java 2007-01-28 21:47:38 UTC (rev 802) @@ -2,6 +2,7 @@ import java.awt.event.ActionListener; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashSet; import java.util.Iterator; @@ -51,6 +52,8 @@ public static interface A { public void test(); + + public void fp() throws IOException; } public static class B implements A @@ -61,10 +64,20 @@ { } + + public void fp() + { + + } } public void actionPerformed(ActionEvent ae) { } + + public void ocpFalseFPDueToExceptionSig(B b) + { + b.fp(); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 21:08:03 UTC (rev 801) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 21:47:38 UTC (rev 802) @@ -29,6 +29,7 @@ import org.apache.bcel.Constants; 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.LocalVariable; @@ -37,6 +38,7 @@ import org.apache.bcel.generic.Type; import com.mebigfatguy.fbcontrib.utils.Integer14; +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; @@ -212,11 +214,8 @@ } } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { - int reg; - if (seen == ALOAD) - reg = this.getRegisterOperand(); - else - reg = seen - ALOAD_0; + int reg = RegisterUtils.getALoadReg(this, seen); + int parm = reg; if (!methodIsStatic) parm--; @@ -254,7 +253,7 @@ parm++; //users expect 1 based parameters String infName = definers.keySet().iterator().next().getClassName(); - bugReporter.reportBug( new BugInstance( this, "OCP_OVERLY_CONCRETE_PARAMETER", NORMAL_PRIORITY) + bugReporter.reportBug( new BugInstance(this, "OCP_OVERLY_CONCRETE_PARAMETER", NORMAL_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(this, 0) @@ -356,6 +355,15 @@ for (MethodInfo mi : methodSigs) { if (methodInfo.equals(mi)) { methodDefined = true; + String[] exceptions = mi.getMethodExceptions(); + if (exceptions != null) { + for (String ex : exceptions) { + if (!isExceptionHandled(ex)) { + methodDefined = false; + break; + } + } + } break; } } @@ -368,6 +376,48 @@ } } + /** + * returns whether this exception is handled either in a try/catch or throws clause at this pc + * + * @param ex the name of the exception + * + * @return whether the exception is handled + */ + private boolean isExceptionHandled(String ex) { + try { + JavaClass thrownEx = Repository.lookupClass(ex); + //First look at the throws clause + ExceptionTable et = getMethod().getExceptionTable(); + if (et != null) { + String[] throwClauseExNames = et.getExceptionNames(); + for (String throwClauseExName : throwClauseExNames) { + JavaClass throwClauseEx = Repository.lookupClass(throwClauseExName); + if (thrownEx.instanceOf(throwClauseEx)) + return true; + } + } + // Next look at the try catch blocks + CodeException[] catchExs = getCode().getExceptionTable(); + if (catchExs != null) { + int pc = getPC(); + for (CodeException catchEx : catchExs) { + if ((pc >= catchEx.getStartPC()) && (pc <= catchEx.getEndPC())) { + int type = catchEx.getCatchType(); + if (type != 0) { + String catchExName = getConstantPool().getConstantString(type, Constants.CONSTANT_Class); + JavaClass catchException = Repository.lookupClass(catchExName); + if (thrownEx.instanceOf(catchException)) + return true; + } + } + } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } + return false; + } + private void removeUselessDefiners(String parmSig, final int reg) { if (parmSig.startsWith("L")) { parmSig = parmSig.substring( 1, parmSig.length() - 1).replace('/', '.'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |