[Fb-contrib-commit] SF.net SVN: fb-contrib:[1525] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2010-04-03 15:25:05
|
Revision: 1525
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1525&view=rev
Author: dbrosius
Date: 2010-04-03 15:24:59 +0000 (Sat, 03 Apr 2010)
Log Message:
-----------
add SPP check for calling System.arraycopy with a non array for either array parms
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 2010-03-15 05:46:12 UTC (rev 1524)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-04-03 15:24:59 UTC (rev 1525)
@@ -209,7 +209,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,SPP_USE_GETPROPERTY,SPP_USELESS_CASING" />
+ 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,SPP_USELESS_CASING,SPP_NON_ARRAY_PARM" />
<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope"
speed="fast" reports="BAS_BLOATED_ASSIGNMENT_SCOPE" hidden="true" />
@@ -327,7 +327,11 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.ImproperPropertiesUse"
speed="fast"
reports="IPU_IMPROPER_PROPERTIES_USE,IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY" />
-
+<!--
+ <Detector class="com.mebigfatguy.fbcontrib.detect.PossibleConstantAllocationInLoop"
+ speed="fast"
+ reports="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP" />
+ -->
<!-- BugPattern -->
<BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING"
@@ -501,6 +505,7 @@
experimental="true" />
<BugPattern abbrev="SPP" type="SPP_SERIALVER_SHOULD_BE_PRIVATE"
category="STYLE" />
+ <BugPattern abbrev="SPP" type="SPP_NON_ARRAY_PARM" category="CORRECTNESS" />
<BugPattern abbrev="BAS" type="BAS_BLOATED_ASSIGNMENT_SCOPE"
category="PERFORMANCE" />
<BugPattern abbrev="SCII"
@@ -620,4 +625,6 @@
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="IPU" type="IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY"
category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="PCAIL" type="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP"
+ category="PERFORMANCE" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-03-15 05:46:12 UTC (rev 1524)
+++ trunk/fb-contrib/etc/messages.xml 2010-04-03 15:24:59 UTC (rev 1525)
@@ -1123,6 +1123,17 @@
]]>
</Details>
</Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.PossibleConstantAllocationInLoop">
+ <Details>
+ <![CDATA[
+ <p>This detector looks for allocations of objects using the default constructor in a loop, where
+ the object allocated is never assigned to any object that is used outside the loop.
+ It is possible that this allocation can be done outside the loop to avoid excessive garbage.</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
<!-- BugPattern -->
@@ -2321,6 +2332,18 @@
concern to case, the toUpperCase or toLowerCase calls are pointless and can be removed.
]]>
</Details>
+ </BugPattern>
+
+ <BugPattern type="SPP_NON_ARRAY_PARM">
+ <ShortDescription>method passes a non array object to a parameter that expects an array</ShortDescription>
+ <LongDescription>method {1} passes a non array object to a parameter that expects an array</LongDescription>
+ <Details>
+ <![CDATA[
+ This method expects an array to be passed as one of its parameters, but unfortunately defines
+ the parameter as Object. This invocation of this method does not pass an array and will throw
+ an exception when run.
+ ]]>
+ </Details>
</BugPattern>
<BugPattern type="BAS_BLOATED_ASSIGNMENT_SCOPE">
@@ -3059,7 +3082,7 @@
</Details>
</BugPattern>
- <BugPattern type="IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY">
+ <BugPattern type="IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY">
<ShortDescription>Method uses Properties.put instead of Properties.setProperty</ShortDescription>
<LongDescription>Method {1} uses Properties.put instead of Properties.setProperty</LongDescription>
<Details>
@@ -3070,6 +3093,18 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP">
+ <ShortDescription>Method allocates an object that is used in a constant way in a loop</ShortDescription>
+ <LongDescription>Method {1} allocates an object that is used in a constant way in a loop</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method allocates an object using the default constructor in a loop, and then
+ only uses it in a quasi-static way. It is never assigned to anything that lives outside
+ the loop, and could potentially be allocated once outside the loop.
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
@@ -3165,4 +3200,5 @@
<BugCode abbrev="MDM">More Dumb Methods</BugCode>
<BugCode abbrev="ROOM">Reflection on Object Methods</BugCode>
<BugCode abbrev="IPU">Improper Properties use</BugCode>
+ <BugCode abbrev="PCAIL">Possible Constant Allocation In Loop</BugCode>
</MessageCollection>
Modified: trunk/fb-contrib/samples/SPP_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SPP_Sample.java 2010-03-15 05:46:12 UTC (rev 1524)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2010-04-03 15:24:59 UTC (rev 1525)
@@ -6,6 +6,7 @@
import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
@@ -292,4 +293,12 @@
i = (int) r.nextFloat();
}
+
+ public void testSAC(List<String> input)
+ {
+ String[] copy = new String[input.size()];
+ System.arraycopy(input, 0, copy, 0, copy.length);
+
+ System.arraycopy(copy, 0, input, 0, copy.length);
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2010-03-15 05:46:12 UTC (rev 1524)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2010-04-03 15:24:59 UTC (rev 1525)
@@ -377,9 +377,27 @@
String className = getClassConstantOperand();
String methodName = getNameConstantOperand();
if ("java/lang/System".equals(className)) {
- if ("getProperties".equals(methodName))
- {
+ if ("getProperties".equals(methodName)) {
userValue = "getProperties";
+ } else if ("arraycopy".equals(methodName)) {
+ if (stack.getStackDepth() >= 5) {
+ OpcodeStack.Item item = stack.getStackItem(2);
+ String sig = item.getSignature();
+ if ((sig.charAt(0) != '[') && !"Ljava/lang/Object;".equals(sig)) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_NON_ARRAY_PARM", HIGH_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ item = stack.getStackItem(4);
+ sig = item.getSignature();
+ if ((sig.charAt(0) != '[') && !"Ljava/lang/Object;".equals(sig)) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_NON_ARRAY_PARM", HIGH_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
}
}
} else if (seen == INVOKEVIRTUAL) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|