Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib:[1448] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2010-01-05 09:02:18
|
Revision: 1448
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1448&view=rev
Author: dbrosius
Date: 2010-01-05 09:02:06 +0000 (Tue, 05 Jan 2010)
Log Message:
-----------
using 1.5 now --> use enums
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java 2010-01-05 08:45:36 UTC (rev 1447)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java 2010-01-05 09:02:06 UTC (rev 1448)
@@ -33,13 +33,11 @@
*/
public class NeedlessInstanceRetrieval extends BytecodeScanningDetector
{
- private static final int SEEN_NOTHING = 0;
- private static final int SEEN_INVOKE = 1;
- private static final int SEEN_POP = 2;
+ enum State {SEEN_NOTHING, SEEN_INVOKE, SEEN_POP}
private BugReporter bugReporter;
private LineNumberTable lnTable;
- private int state;
+ private State state;
private int invokePC;
/**
* constructs a NIR detector given the reporter to report bugs on
@@ -59,7 +57,7 @@
try {
lnTable = obj.getLineNumberTable();
if (lnTable != null) {
- state = SEEN_NOTHING;
+ state = State.SEEN_NOTHING;
super.visitCode(obj);
}
} finally {
@@ -87,7 +85,7 @@
if (!"java/lang/Object".equals(clsName)
&& !"java/lang/String".equals(clsName)) {
invokePC = getPC();
- state = SEEN_INVOKE;
+ state = State.SEEN_INVOKE;
}
}
}
@@ -95,9 +93,9 @@
case SEEN_INVOKE:
if (seen == POP)
- state = SEEN_POP;
+ state = State.SEEN_POP;
else
- state = SEEN_NOTHING;
+ state = State.SEEN_NOTHING;
break;
case SEEN_POP:
@@ -109,11 +107,11 @@
.addSourceLine(this));
}
}
- state = SEEN_NOTHING;
+ state = State.SEEN_NOTHING;
break;
default:
- state = SEEN_NOTHING;
+ state = State.SEEN_NOTHING;
break;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-08-22 04:43:34
|
Revision: 1590
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1590&view=rev
Author: dbrosius
Date: 2010-08-22 04:43:28 +0000 (Sun, 22 Aug 2010)
Log Message:
-----------
catch someMethod().staticMethod();
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java 2010-08-22 04:40:23 UTC (rev 1589)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java 2010-08-22 04:43:28 UTC (rev 1590)
@@ -35,7 +35,7 @@
{
enum State {SEEN_NOTHING, SEEN_INVOKE, SEEN_POP}
- private BugReporter bugReporter;
+ private final BugReporter bugReporter;
private LineNumberTable lnTable;
private State state;
private int invokePC;
@@ -58,6 +58,7 @@
lnTable = obj.getLineNumberTable();
if (lnTable != null) {
state = State.SEEN_NOTHING;
+ invokePC = -1;
super.visitCode(obj);
}
} finally {
@@ -76,8 +77,8 @@
switch (state)
{
case SEEN_NOTHING:
- if ((seen == INVOKEINTERFACE)
- || (seen == INVOKEVIRTUAL)) {
+ if (seen == INVOKEINTERFACE
+ || seen == INVOKEVIRTUAL) {
String sig = getSigConstantOperand();
Type retType = Type.getReturnType(sig);
if (retType.getSignature().startsWith("L")) {
@@ -99,7 +100,7 @@
break;
case SEEN_POP:
- if ((seen >= ACONST_NULL) && (seen <= DCONST_1)) {
+ if (seen >= ACONST_NULL && seen <= DCONST_1 || seen == INVOKESTATIC) {
if (lnTable.getSourceLine(invokePC) == lnTable.getSourceLine(getPC())) {
bugReporter.reportBug(new BugInstance(this, "NIR_NEEDLESS_INSTANCE_RETRIEVAL", NORMAL_PRIORITY)
.addClass(this)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2011-07-04 02:41:45
|
Revision: 1697
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1697&view=rev
Author: dbrosius
Date: 2011-07-04 02:41:38 +0000 (Mon, 04 Jul 2011)
Log Message:
-----------
fix some fp for NIR
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java 2011-07-03 05:37:51 UTC (rev 1696)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java 2011-07-04 02:41:38 UTC (rev 1697)
@@ -39,6 +39,7 @@
private LineNumberTable lnTable;
private State state;
private int invokePC;
+ private String returnType;
/**
* constructs a NIR detector given the reporter to report bugs on
* @param bugReporter the sync of bug reports
@@ -59,6 +60,7 @@
if (lnTable != null) {
state = State.SEEN_NOTHING;
invokePC = -1;
+ returnType = null;
super.visitCode(obj);
}
} finally {
@@ -85,6 +87,8 @@
String clsName = getClassConstantOperand();
if (!"java/lang/Object".equals(clsName)
&& !"java/lang/String".equals(clsName)) {
+ returnType = retType.getSignature();
+ returnType = returnType.substring(1, returnType.length() - 1);
invokePC = getPC();
state = State.SEEN_INVOKE;
}
@@ -95,24 +99,35 @@
case SEEN_INVOKE:
if (seen == POP)
state = State.SEEN_POP;
- else
+ else {
state = State.SEEN_NOTHING;
+ returnType = null;
+ }
break;
case SEEN_POP:
- if (seen >= ACONST_NULL && seen <= DCONST_1 || seen == INVOKESTATIC) {
- if (lnTable.getSourceLine(invokePC) == lnTable.getSourceLine(getPC())) {
- bugReporter.reportBug(new BugInstance(this, "NIR_NEEDLESS_INSTANCE_RETRIEVAL", NORMAL_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
- }
+ if ((seen >= ACONST_NULL && seen <= DCONST_1) || (seen == GETFIELD)) {
+ state = State.SEEN_POP;
+ } else if ((seen == INVOKESTATIC) || (seen == GETSTATIC)) {
+ if (getClassConstantOperand().equals(returnType)) {
+ if (lnTable.getSourceLine(invokePC) == lnTable.getSourceLine(getPC())) {
+ bugReporter.reportBug(new BugInstance(this, "NIR_NEEDLESS_INSTANCE_RETRIEVAL", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ state = State.SEEN_NOTHING;
+ returnType = null;
+ } else {
+ state = State.SEEN_NOTHING;
+ returnType = null;
}
- state = State.SEEN_NOTHING;
break;
default:
state = State.SEEN_NOTHING;
+ returnType = null;
break;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|