[Fb-contrib-commit] SF.net SVN: fb-contrib:[1714] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2012-02-03 23:16:32
|
Revision: 1714
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1714&view=rev
Author: dbrosius
Date: 2012-02-03 23:16:26 +0000 (Fri, 03 Feb 2012)
Log Message:
-----------
update from github
Modified Paths:
--------------
trunk/fb-contrib/samples/STB_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StackedTryBlocks.java
Modified: trunk/fb-contrib/samples/STB_Sample.java
===================================================================
--- trunk/fb-contrib/samples/STB_Sample.java 2012-02-02 18:31:49 UTC (rev 1713)
+++ trunk/fb-contrib/samples/STB_Sample.java 2012-02-03 23:16:26 UTC (rev 1714)
@@ -31,7 +31,42 @@
throw new STBException();
}
}
+
+ public void fpTestDiffMessages(File f1, File f2) throws STBException {
+ try {
+ InputStream is = new FileInputStream(f1);
+ } catch (IOException ioe) {
+ throw new STBException("Couldn't open file 1");
+ }
+ try {
+ InputStream is = new FileInputStream(f2);
+ } catch (IOException ioe) {
+ throw new STBException("Couldn't open file 2");
+ }
+ }
+
+ public void fpTestDiffMessagesByAppending(File f1, File f2) throws STBException {
+ try {
+ InputStream is = new FileInputStream(f1);
+ } catch (IOException ioe) {
+ throw new STBException("Couldn't open file: " + f1);
+ }
+
+ try {
+ InputStream is = new FileInputStream(f2);
+ } catch (IOException ioe) {
+ throw new STBException("Couldn't open file: " + f2);
+ }
+ }
+
static class STBException extends Exception {
+
+ public STBException() {
+ }
+
+ public STBException(String message) {
+ super(message);
+ }
}
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StackedTryBlocks.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StackedTryBlocks.java 2012-02-02 18:31:49 UTC (rev 1713)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StackedTryBlocks.java 2012-02-03 23:16:26 UTC (rev 1714)
@@ -9,10 +9,13 @@
import java.util.Set;
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.ConstantClass;
import org.apache.bcel.classfile.ConstantPool;
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.generic.Type;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
@@ -29,6 +32,15 @@
public class StackedTryBlocks extends BytecodeScanningDetector {
+ private static JavaClass THROWABLE_CLASS;
+
+ static {
+ try {
+ THROWABLE_CLASS = Repository.lookupClass("java.lang.Throwable");
+ } catch (ClassNotFoundException cnfe) {
+ THROWABLE_CLASS = null;
+ }
+ }
private final BugReporter bugReporter;
private List<TryBlock> blocks;
private List<TryBlock> inBlocks;
@@ -41,8 +53,10 @@
@Override
public void visitClassContext(ClassContext classContext) {
try {
- stack = new OpcodeStack();
- super.visitClassContext(classContext);
+ if (THROWABLE_CLASS != null) {
+ stack = new OpcodeStack();
+ super.visitClassContext(classContext);
+ }
} finally {
stack = null;
}
@@ -54,8 +68,7 @@
try {
XMethod xMethod = getXMethod();
String[] tes = xMethod.getThrownExceptions();
- Set<String> thrownExceptions = new HashSet<String>(Arrays.<String> asList((tes == null) ? new String[0]
- : tes));
+ Set<String> thrownExceptions = new HashSet<String>(Arrays.<String> asList((tes == null) ? new String[0] : tes));
blocks = new ArrayList<TryBlock>();
inBlocks = new ArrayList<TryBlock>();
@@ -91,7 +104,9 @@
TryBlock secondBlock = blocks.get(i);
if ((firstBlock.getCatchType() == secondBlock.getCatchType())
- && (firstBlock.getThrowSignature().equals(secondBlock.getThrowSignature()))) {
+ && (firstBlock.getThrowSignature().equals(secondBlock.getThrowSignature())
+ && (firstBlock.getMessage().equals(secondBlock.getMessage())
+ && (firstBlock.getExceptionSignature().equals(secondBlock.getExceptionSignature()))))) {
bugReporter.reportBug(new BugInstance(this, "STB_STACKED_TRY_BLOCKS", NORMAL_PRIORITY)
.addClass(this).addMethod(this)
.addSourceLineRange(this, firstBlock.getStartPC(), firstBlock.getEndHandlerPC())
@@ -112,6 +127,7 @@
@Override
public void sawOpcode(int seen) {
+ String message = null;
try {
int pc = getPC();
TryBlock block = findBlockWithStart(pc);
@@ -146,16 +162,44 @@
} else if (seen == ATHROW) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
- innerBlock.setThrowSignature(item.getSignature());
+ XMethod xm = item.getReturnValueOf();
+ if (xm != null) {
+ innerBlock.setThrowSignature(xm.getSignature());
+ }
+ innerBlock.setExceptionSignature(item.getSignature());
+ innerBlock.setMessage((String) item.getUserValue());
} else {
inBlocks.remove(inBlocks.size() - 1);
innerBlock.setState(TryBlock.State.AFTER);
}
+ } else if ((seen == INVOKESPECIAL) && "<init>".equals(getNameConstantOperand())) {
+ String cls = getClassConstantOperand();
+ JavaClass exCls = Repository.lookupClass(cls);
+ if (exCls.instanceOf(THROWABLE_CLASS)) {
+ String signature = getSigConstantOperand();
+ Type[] types = Type.getArgumentTypes(signature);
+ if ((types.length > 0) && "Ljava/lang/String;".equals(types[0].getSignature())) {
+ if (stack.getStackDepth() >= types.length) {
+ OpcodeStack.Item item = stack.getStackItem(types.length - 1);
+ message = (String)item.getConstant();
+ if (message == null) {
+ message = "____UNKNOWN____" + System.currentTimeMillis();
+ }
+ }
+ }
+
+ }
}
}
}
+ } catch (ClassNotFoundException cnfe) {
+ bugReporter.reportMissingClass(cnfe);
} finally {
stack.sawOpcode(this, seen);
+ if ((message != null) && (stack.getStackDepth() > 0)) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ item.setUserValue(message);
+ }
}
}
@@ -181,7 +225,9 @@
int handlerPC;
int endHandlerPC;
BitSet catchTypes;
+ String exSig;
String throwSig;
+ String message;
State state;
public TryBlock(CodeException ce) {
@@ -228,13 +274,29 @@
endHandlerPC = end;
}
+ public void setExceptionSignature(String sig) {
+ exSig = sig;
+ }
+
public void setThrowSignature(String sig) {
throwSig = sig;
}
+
+ public void setMessage(String m) {
+ message = m;
+ }
+ public String getExceptionSignature() {
+ return (exSig == null) ? String.valueOf(System.identityHashCode(this)) : exSig;
+ }
+
public String getThrowSignature() {
return (throwSig == null) ? String.valueOf(System.identityHashCode(this)) : throwSig;
}
+
+ public String getMessage() {
+ return (message == null) ? String.valueOf(System.identityHashCode(this)) : message;
+ }
public int getStartPC() {
return startPC;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|