[Fb-contrib-commit] SF.net SVN: fb-contrib:[1629] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2010-10-14 04:46:37
|
Revision: 1629
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1629&view=rev
Author: dbrosius
Date: 2010-10-14 04:46:30 +0000 (Thu, 14 Oct 2010)
Log Message:
-----------
add test for transient trims in SPP
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-10-14 04:45:37 UTC (rev 1628)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-10-14 04:46:30 UTC (rev 1629)
@@ -132,7 +132,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparatorReturnValues" speed="fast" reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" />
<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,SPP_NON_ARRAY_PARM,SPP_EMPTY_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,SPP_EMPTY_CASING,SPP_TEMPORARY_TRIM" />
<!--
<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" reports="BAS_BLOATED_ASSIGNMENT_SCOPE" hidden="true" />
-->
@@ -193,9 +193,9 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.PoorlyDefinedParameter" speed="fast" reports="PDP_POORLY_DEFINED_PARAMETER" />
<Detector class="com.mebigfatguy.fbcontrib.detect.NonSymmetricEquals" speed="fast" reports="NSE_NON_SYMMETRIC_EQUALS" />
-<!--
+<!-- -->
<Detector class="com.mebigfatguy.fbcontrib.detect.ContraVariantArrayAssignment" speed="fast" hidden="true" reports="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT,CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT" />
- -->
+<!-- -->
<Detector class="com.mebigfatguy.fbcontrib.detect.NonFunctionalField" speed="fast" reports="NFF_NON_FUNCTIONAL_FIELD" />
@@ -315,6 +315,7 @@
<BugPattern abbrev="SPP" type="SPP_SERIALVER_SHOULD_BE_PRIVATE" category="STYLE" />
<BugPattern abbrev="SPP" type="SPP_NON_ARRAY_PARM" category="CORRECTNESS" />
<BugPattern abbrev="SPP" type="SPP_EMPTY_CASING" category="STYLE" />
+ <BugPattern abbrev="SPP" type="SPP_TEMPORARY_TRIM" 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 2010-10-14 04:45:37 UTC (rev 1628)
+++ trunk/fb-contrib/etc/messages.xml 2010-10-14 04:46:30 UTC (rev 1629)
@@ -2413,7 +2413,21 @@
]]>
</Details>
</BugPattern>
-
+
+ <BugPattern type="SPP_TEMPORARY_TRIM">
+ <ShortDescription>Method trims a String temporarily</ShortDescription>
+ <LongDescription>Method {1} trims a String temporarily</LongDescription>
+ <Details>
+ <![CDATA[
+ This method calls trim() on a String without assigning the new string to another variable.
+ It then calls length() or equals on this trimmed string. If trimming the string was important
+ for determining it's length of it's equality, it should be trimmed when you actually go to use it.
+ It would make more sense to first trim the String, store the trimmed value in a variable, and then
+ continue to test and use that trimmed string.
+ ]]>
+ </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 2010-10-14 04:45:37 UTC (rev 1628)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2010-10-14 04:46:30 UTC (rev 1629)
@@ -321,4 +321,15 @@
{
return (s.equalsIgnoreCase(""));
}
+
+ public void testTrim(String s)
+ {
+ if (s.trim().length() > 0)
+ System.out.println(s);
+
+ if (s.trim().equals("Booyah"))
+ {
+ System.out.println("Booyah->" + s);
+ }
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2010-10-14 04:45:37 UTC (rev 1628)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2010-10-14 04:46:30 UTC (rev 1629)
@@ -482,6 +482,28 @@
.addSourceLine(this));
}
}
+ } else if ("trim".equals(methodName)) {
+ userValue = "trim";
+ } else if ("length".equals(methodName)) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ if ("trim".equals(item.getUserValue())) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_TEMPORARY_TRIM", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ } else if ("equals".equals(methodName)) {
+ if (stack.getStackDepth() > 1) {
+ OpcodeStack.Item item = stack.getStackItem(1);
+ if ("trim".equals(item.getUserValue())) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_TEMPORARY_TRIM", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
}
} else if ("equals(Ljava/lang/Object;)Z".equals(methodName + getSigConstantOperand())) {
try {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|