[Fb-contrib-commit] SF.net SVN: fb-contrib:[1088] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-02-14 16:30:34
|
Revision: 1088
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1088&view=rev
Author: dbrosius
Date: 2009-02-14 16:30:31 +0000 (Sat, 14 Feb 2009)
Log Message:
-----------
add check for System.getProperties().getProperty("foo")
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/samples/SPP_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2009-02-14 05:08:05 UTC (rev 1087)
+++ trunk/fb-contrib/etc/findbugs.xml 2009-02-14 16:30:31 UTC (rev 1088)
@@ -256,7 +256,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri"
speed="fast"
- reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM,SPP_INVALID_BOOLEAN_NULL_CHECK,SPP_USE_CHARAT,SPP_USELESS_TRINARY,SPP_SUSPECT_STRING_TEST,SPP_USE_STRINGBUILDER_LENGTH,SPP_INVALID_CALENDAR_COMPARE,SPP_USE_CONTAINSKEY,SPP_USE_ISEMPTY" />
+ reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM,SPP_INVALID_BOOLEAN_NULL_CHECK,SPP_USE_CHARAT,SPP_USELESS_TRINARY,SPP_SUSPECT_STRING_TEST,SPP_USE_STRINGBUILDER_LENGTH,SPP_INVALID_CALENDAR_COMPARE,SPP_USE_CONTAINSKEY,SPP_USE_ISEMPTY,SPP_USE_GETPROPERTY" />
<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope"
speed="fast"
@@ -413,6 +413,7 @@
<BugPattern abbrev="SPP" type="SPP_INVALID_CALENDAR_COMPARE" category="CORRECTNESS"/>
<BugPattern abbrev="SPP" type="SPP_USE_CONTAINSKEY" category="STYLE"/>
<BugPattern abbrev="SPP" type="SPP_USE_ISEMPTY" category="STYLE"/>
+ <BugPattern abbrev="SPP" type="SPP_USE_GETPROPERTY" category="STYLE"/>
<BugPattern abbrev="BAS" type="BAS_BLOATED_ASSIGNMENT_SCOPE" category="PERFORMANCE" />
<BugPattern abbrev="SCII" type="SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR" category="STYLE" />
<BugPattern abbrev="DWI" type="DWI_DELETING_WHILE_ITERATING" category="CORRECTNESS" />
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2009-02-14 05:08:05 UTC (rev 1087)
+++ trunk/fb-contrib/etc/messages.xml 2009-02-14 16:30:31 UTC (rev 1088)
@@ -2037,6 +2037,21 @@
</Details>
</BugPattern>
+ <BugPattern type="SPP_USE_GETPROPERTY">
+ <ShortDescription>Method calls getProperties just to get one property, use getProperty instead</ShortDescription>
+ <LongDescription>Method {1} calls getProperties just to get one property, use getProperty instead</LongDescription>
+ <Details>
+ <![CDATA[
+ <table>
+ <tr><td>This method uses</td></tr>
+ <tr><td>String prop = System.getProperties().getProperty("foo");</td></tr
+ <tr><td>instead of simply using</td></tr>
+ <tr><td>String prop = System.getProperty("foo");</td></tr>
+ </table>
+ ]]>
+ </Details>
+ </BugPattern>
+
<BugPattern type="BAS_BLOATED_ASSIGNMENT_SCOPE">
<ShortDescription>Method assigns a variable in a larger scope then is needed</ShortDescription>
<LongDescription>Method {1} assigns a variable in a larger scope then is needed</LongDescription>
Modified: trunk/fb-contrib/samples/SPP_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SPP_Sample.java 2009-02-14 05:08:05 UTC (rev 1087)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2009-02-14 16:30:31 UTC (rev 1088)
@@ -2,6 +2,7 @@
import java.util.BitSet;
import java.util.Calendar;
import java.util.Date;
+import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
@@ -202,4 +203,17 @@
if (s.size() == 0)
System.out.println("empty");
}
+
+ public boolean testDerivedGregorianCalendar()
+ {
+ Calendar c = new GregorianCalendar() {};
+ Calendar s = new GregorianCalendar();
+
+ return s.after(c);
+ }
+
+ public void testGetProperties()
+ {
+ String lf = System.getProperties().getProperty("line.separator");
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2009-02-14 05:08:05 UTC (rev 1087)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2009-02-14 16:30:31 UTC (rev 1088)
@@ -358,6 +358,13 @@
.addSourceLine(this));
}
}
+ } else if (seen == INVOKESTATIC) {
+ String className = getClassConstantOperand();
+ String methodName = getNameConstantOperand();
+ if ("java/lang/System".equals(className)) {
+ if ("getProperties".equals(methodName))
+ userValue = "getProperties";
+ }
} else if (seen == INVOKEVIRTUAL) {
String className = getClassConstantOperand();
String methodName = getNameConstantOperand();
@@ -457,6 +464,18 @@
}
}
+ } else if ("java/util/Properties".equals(className)) {
+ if (("get".equals(methodName) || "getProperty".equals(methodName))) {
+ if (stack.getStackDepth() > 1) {
+ OpcodeStack.Item item = stack.getStackItem(1);
+ if ("getProperties".equals(item.getUserValue())) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_USE_GETPROPERTY", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
}
} else if (seen == INVOKESPECIAL) {
String className = getClassConstantOperand();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|