Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29797/src/com/mebigfatguy/fbcontrib/detect
Modified Files:
AbnormalFinallyBlockReturn.java
Log Message:
afbr is somewhat working
Index: AbnormalFinallyBlockReturn.java
===================================================================
RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- AbnormalFinallyBlockReturn.java 8 Nov 2005 05:43:42 -0000 1.2
+++ AbnormalFinallyBlockReturn.java 10 Nov 2005 01:53:49 -0000 1.3
@@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.bcel.Constants;
import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.CodeException;
@@ -28,11 +29,15 @@
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
import edu.umd.cs.findbugs.StatelessDetector;
+import edu.umd.cs.findbugs.ba.ClassContext;
+import edu.umd.cs.findbugs.visitclass.Constants2;
public class AbnormalFinallyBlockReturn extends BytecodeScanningDetector implements StatelessDetector {
private BugReporter bugReporter;
private CodeException[] exc;
private List<FinallyBlockInfo> fbInfo = new ArrayList<FinallyBlockInfo>();
+ private int majorVersion;
+ private int loadedReg;
public AbnormalFinallyBlockReturn(final BugReporter bugReporter) {
this.bugReporter = bugReporter;
@@ -41,51 +46,52 @@
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
+
+ public void visitClassContext(ClassContext classContext) {
+ majorVersion = classContext.getJavaClass().getMajor();
+ if (majorVersion >= MAJOR_1_4)
+ super.visitClassContext(classContext);
+ }
public void visitCode(Code obj) {
fbInfo.clear();
+ loadedReg = -1;
+
exc = obj.getExceptionTable();
if (exc != null) {
for (CodeException ce : exc) {
if ((ce.getCatchType() == 0)
&& (ce.getStartPC() == ce.getHandlerPC())) {
- fbInfo.add(new FinallyBlockInfo(ce.getStartPC(), ce.getEndPC()));
+ fbInfo.add(new FinallyBlockInfo(ce.getStartPC(), ce.getEndPC()));
}
}
- }
-
+ }
+
if (fbInfo.size() > 0)
super.visitCode(obj);
}
-
- public void sawOpcode(int seen) {
- if (fbInfo.size() == 0)
- return;
-
+
+ public void sawOpcode(int seen) {
+ if (fbInfo.size() == 0)
+ return;
+
FinallyBlockInfo fbi = fbInfo.get(0);
- if ((seen == GOTO) && ((getPC() + 3) == fbi.startPC)) {
- fbi.afterFinallyPC = getBranchTarget();
- return;
- } else if ((seen == ATHROW) && ((getPC() + 1) == fbi.startPC)) {
- fbi.afterFinallyPC = getMaxPC() + 1;
- return;
- }
-
if (getPC() < fbi.startPC)
return;
-
- if ((getPC() == fbi.startPC) && (fbi.afterFinallyPC == 0)) {
- fbInfo.remove(0);
- sawOpcode(seen);
- return;
- }
-
- if (getPC() >= fbi.afterFinallyPC) {
- fbInfo.remove(0);
- sawOpcode(seen);
- return;
- }
+
+ if (getPC() == fbi.startPC) {
+ if (seen == ASTORE)
+ fbi.exReg = getRegisterOperand();
+ else if ((seen >= ASTORE_0) && (seen <= ASTORE_3))
+ fbi.exReg = seen - ASTORE_0;
+ else {
+ fbInfo.remove(0);
+ sawOpcode(seen);
+ return;
+ }
+ return;
+ }
if (seen == MONITORENTER) {
fbi.monitorCount++;
@@ -97,7 +103,19 @@
return;
}
}
-
+
+ if ((seen == ATHROW) && (loadedReg == fbi.exReg)) {
+ fbInfo.remove(0);
+ sawOpcode(seen);
+ return;
+ }
+ else if (seen == ALOAD)
+ loadedReg = getRegisterOperand();
+ else if ((seen >= ALOAD_0) && (seen <= ALOAD_3))
+ loadedReg = seen - ALOAD_0;
+ else
+ loadedReg = -1;
+
if (((seen >= IRETURN) && (seen <= RETURN)) || (seen == ATHROW)) {
bugReporter.reportBug(new BugInstance( this, "AFBR_ABNORMAL_FINALLY_BLOCK_RETURN", NORMAL_PRIORITY)
.addClass(this)
@@ -111,14 +129,14 @@
{
public int startPC;
public int endPC;
- public int afterFinallyPC;
public int monitorCount;
+ public int exReg;
public FinallyBlockInfo(int start, int end) {
startPC = start;
endPC = end;
- afterFinallyPC = 0;
monitorCount = 0;
+ exReg = -1;
}
}
-}
+}
\ No newline at end of file
|