[Fb-contrib-commit] SF.net SVN: fb-contrib:[1435] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2010-01-05 06:49:15
|
Revision: 1435
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1435&view=rev
Author: dbrosius
Date: 2010-01-05 06:49:08 +0000 (Tue, 05 Jan 2010)
Log Message:
-----------
using 1.5 -> use enums
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java 2010-01-05 06:45:42 UTC (rev 1434)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java 2010-01-05 06:49:08 UTC (rev 1435)
@@ -41,10 +41,9 @@
*/
public class ConstantListIndex extends BytecodeScanningDetector
{
+ enum State {SeenNothing, SeenConstant_0, SeenConstant};
+
private static final String MAX_ICONST0_LOOP_DISTANCE_PROPERTY = "fb-contrib.cli.maxloopdistance";
- private static final int SEEN_NOTHING = 0;
- private static final int SEEN_CONSTANT_0 = 1;
- private static final int SEEN_CONSTANT = 2;
private static final Set<String> ubiquitousMethods = new HashSet<String>();
static {
ubiquitousMethods.add("java.lang.String.split(Ljava/lang/String;)[Ljava/lang/String;");
@@ -52,7 +51,7 @@
private final BugReporter bugReporter;
- private int state;
+ private State state;
private Set<Integer> iConst0Looped;
private final int max_iConst0LoopDistance;
private OpcodeStack stack;
@@ -90,7 +89,7 @@
*/
@Override
public void visitMethod(Method obj) {
- state = SEEN_NOTHING;
+ state = State.SeenNothing;
iConst0Looped.clear();
stack.resetForMethodEntry(this);
}
@@ -104,20 +103,20 @@
public void sawOpcode(int seen) {
try {
switch (state) {
- case SEEN_NOTHING:
+ case SeenNothing:
if (seen == ICONST_0)
- state = SEEN_CONSTANT_0;
+ state = State.SeenConstant_0;
else if ((seen >= ICONST_1) && (seen <= ICONST_5))
- state = SEEN_CONSTANT;
+ state = State.SeenConstant;
else if ((seen == LDC) || (seen == LDC_W)) {
Constant c = getConstantRefOperand();
if (c instanceof ConstantInteger)
- state = SEEN_CONSTANT;
+ state = State.SeenConstant;
}
break;
- case SEEN_CONSTANT_0:
- case SEEN_CONSTANT:
+ case SeenConstant_0:
+ case SeenConstant:
switch (seen) {
case AALOAD:
if ("main".equals(this.getMethodName()))
@@ -130,7 +129,7 @@
//case BALOAD: byte and char indexing seems prevalent, and
//case CALOAD: usually harmless so ignore
case SALOAD:
- if (state == SEEN_CONSTANT_0)
+ if (state == State.SeenConstant_0)
iConst0Looped.add(Integer.valueOf(getPC()));
else {
if (stack.getStackDepth() > 1) {
@@ -150,7 +149,7 @@
if ("java/util/List".equals(getClassConstantOperand())) {
String methodName = getNameConstantOperand();
if ("get".equals(methodName)) {
- if (state == SEEN_CONSTANT_0)
+ if (state == State.SeenConstant_0)
iConst0Looped.add(Integer.valueOf(getPC()));
else {
bugReporter.reportBug(new BugInstance(this, "CLI_CONSTANT_LIST_INDEX", NORMAL_PRIORITY)
@@ -162,7 +161,7 @@
}
break;
}
- state = SEEN_NOTHING;
+ state = State.SeenNothing;
break;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|