[Fb-contrib-commit] SF.net SVN: fb-contrib:[1073] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-10-05 04:24:39
|
Revision: 1073
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1073&view=rev
Author: dbrosius
Date: 2008-10-05 03:19:29 +0000 (Sun, 05 Oct 2008)
Log Message:
-----------
add test SPP_USE_ISEMPTY
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/htdocs/index.html
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 2008-08-09 03:34:47 UTC (rev 1072)
+++ trunk/fb-contrib/etc/findbugs.xml 2008-10-05 03:19:29 UTC (rev 1073)
@@ -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" />
+ 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" />
<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope"
speed="fast"
@@ -412,6 +412,7 @@
<BugPattern abbrev="SPP" type="SPP_USE_STRINGBUILDER_LENGTH" category="PERFORMANCE" />
<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="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 2008-08-09 03:34:47 UTC (rev 1072)
+++ trunk/fb-contrib/etc/messages.xml 2008-10-05 03:19:29 UTC (rev 1073)
@@ -2026,6 +2026,17 @@
</Details>
</BugPattern>
+ <BugPattern type="SPP_USE_ISEMPTY">
+ <ShortDescription>Method checks the size of a collection against zero rather than using isEmpty()</ShortDescription>
+ <LongDescription>Method {1} checks the size of a collection against zero rather than using isEmpty()</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method calls the size() method on a collection and compares the result to zero to see if the collection
+ is empty. For better code clarity, it is better to just use col.isEmpty() or !col.isEmpty()</p>
+ ]]>
+ </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/htdocs/index.html
===================================================================
--- trunk/fb-contrib/htdocs/index.html 2008-08-09 03:34:47 UTC (rev 1072)
+++ trunk/fb-contrib/htdocs/index.html 2008-10-05 03:19:29 UTC (rev 1073)
@@ -48,9 +48,9 @@
<a href="bugdescriptions.html">Bug Descriptions</a>
<hr/>
- <img id="svn_image" src="flip1.gif" onClick="toggleBlock('svn', 'svn_image');" align="top"/>
+ <img id="svn_image" src="flip2.gif" onClick="toggleBlock('svn', 'svn_image');" align="top"/>
Detectors added in svn<br/>
- <div id="svn" style="display:none;">
+ <div id="svn" style="display:block;">
<ul>
<li><b>[LO] Logger Oddities</b><br/>
Looks for uses of log4j or slf4j where the class specified when creating the logger
@@ -62,9 +62,9 @@
</ul>
</div>
<hr/>
- <img id="v3_6_0_image" src="flip2.gif" onClick="toggleBlock('v3_6_0', 'v3_6_0_image');" align="top"/>
+ <img id="v3_6_0_image" src="flip1.gif" onClick="toggleBlock('v3_6_0', 'v3_6_0_image');" align="top"/>
Detectors added in v3.6.0<br/>
- <div id="v3_6_0" style="display:block;">
+ <div id="v3_6_0" style="display:none;">
<ul>
<li><b>[CFS] Confusing Function Semantics</b><br/>
Looks for methods that return a parameter after making what looks like
Modified: trunk/fb-contrib/samples/SPP_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SPP_Sample.java 2008-08-09 03:34:47 UTC (rev 1072)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2008-10-05 03:19:29 UTC (rev 1073)
@@ -196,4 +196,10 @@
if (m.keySet().contains("Foo"))
System.out.println("Yup");
}
+
+ public void testCollectionSizeEqualsZero(Set<String> s)
+ {
+ if (s.size() == 0)
+ System.out.println("empty");
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2008-08-09 03:34:47 UTC (rev 1072)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2008-10-05 03:19:29 UTC (rev 1073)
@@ -52,6 +52,16 @@
*/
public class SillynessPotPourri extends BytecodeScanningDetector
{
+ private static final Set<String> collectionInterfaces = new HashSet<String>();
+ static {
+ collectionInterfaces.add("java/util/Collection");
+ collectionInterfaces.add("java/util/List");
+ collectionInterfaces.add("java/util/Set");
+ collectionInterfaces.add("java/util/SortedSet");
+ collectionInterfaces.add("java/util/Map");
+ collectionInterfaces.add("java/util/SortedMap");
+ }
+
private final BugReporter bugReporter;
private OpcodeStack stack;
private int lastPCs[];
@@ -155,6 +165,18 @@
}
}
+ if ((seen == IFEQ) || (seen == IFNE)) {
+ if (stack.getStackDepth() == 1) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ if ("size".equals(item.getUserValue())) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_USE_ISEMPTY", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+
if (seen == IFNE) {
byte[] bytes = getCode().getCode();
if (lastPCs[2] != -1) {
@@ -493,6 +515,13 @@
}
}
}
+
+ if (collectionInterfaces.contains(className)) {
+ String method = getNameConstantOperand();
+ if ("size".equals(method)) {
+ userValue = "size";
+ }
+ }
}
} finally {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|