[Fb-contrib-commit] SF.net SVN: fb-contrib: [925] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
From: <dbr...@us...> - 2007-10-07 23:41:45
|
Revision: 925 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=925&view=rev Author: dbrosius Date: 2007-10-07 16:41:34 -0700 (Sun, 07 Oct 2007) Log Message: ----------- if it's possible the pc is in a catch block that caught a runtime exception, don't report. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-07 22:38:41 UTC (rev 924) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-07 23:41:34 UTC (rev 925) @@ -20,11 +20,13 @@ import java.util.ArrayList; import java.util.BitSet; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.Set; import org.apache.bcel.Constants; import org.apache.bcel.Repository; @@ -141,12 +143,24 @@ JavaClass exClass = itm.getJavaClass(); if (exClass.instanceOf(runtimeClass)) { if (catchInfos.size() > 0) { - String catchSignature = catchInfos.get(catchInfos.size() - 1).getSignature(); - - bugReporter.reportBug(new BugInstance(this, "EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + Set<String> possibleCatchSignatures = findPossibleCatchSignatures(catchInfos, pc); + if (!possibleCatchSignatures.contains(exClass.getClassName())) { + boolean anyRuntimes = false; + for (String possibleCatches : possibleCatchSignatures) { + exClass = Repository.lookupClass(possibleCatches); + if (exClass.instanceOf(runtimeClass)) { + anyRuntimes = true; + break; + } + } + + if (!anyRuntimes) { + bugReporter.reportBug(new BugInstance(this, "EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } } } } @@ -199,6 +213,28 @@ } } + /** returns an array of catch types that the current pc is in + * + * @param catchInfos the list of catch infos for this method + * @param pc the current pc + * @return an set of catch exception types that the pc is currently in + */ + public Set<String> findPossibleCatchSignatures(List<CatchInfo> catchInfos, int pc) + { + Set<String> catchTypes = new HashSet<String>(); + ListIterator<CatchInfo> it = catchInfos.listIterator(catchInfos.size()); + while (it.hasPrevious()) { + CatchInfo ci = it.previous(); + if ((pc >= ci.getStart()) && (pc < ci.getFinish())) { + catchTypes.add(ci.getSignature()); + } else { + break; + } + } + + return catchTypes; + } + /** returns whether a method explicitly throws an exception * * @param method the currently parsed method This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |