[Fb-contrib-commit] SF.net SVN: fb-contrib: [935] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2007-10-13 03:30:41
|
Revision: 935 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=935&view=rev Author: dbrosius Date: 2007-10-12 20:30:42 -0700 (Fri, 12 Oct 2007) Log Message: ----------- add SPP_USELESS_TRINARY to the SPP detector 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 2007-10-12 01:51:10 UTC (rev 934) +++ trunk/fb-contrib/etc/findbugs.xml 2007-10-13 03:30:42 UTC (rev 935) @@ -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" /> + 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" /> <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" @@ -381,6 +381,7 @@ <BugPattern abbrev="SPP" type="SPP_EQUALS_ON_ENUM" category="CORRECTNESS" /> <BugPattern abbrev="SPP" type="SPP_INVALID_BOOLEAN_NULL_CHECK" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_USE_CHARAT" category="PERFORMANCE" experimental="true" /> + <BugPattern abbrev="SPP" type="SPP_USELESS_TRINARY" category="PERFORMANCE" experimental="true" /> <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 2007-10-12 01:51:10 UTC (rev 934) +++ trunk/fb-contrib/etc/messages.xml 2007-10-13 03:30:42 UTC (rev 935) @@ -1869,6 +1869,17 @@ </Details> </BugPattern> + <BugPattern type="SPP_USELESS_TRINARY"> + <ShortDescription>Method uses a trinary operator to cast a boolean to true or false</ShortDescription> + <LongDescription>Method {1} uses a trinary operator to cast a boolean to true or false</LongDescription> + <Details> + <![CDATA[ + <p>This method tests the value of a boolean and using a trinary operator to return either true or false. + The trinary operator is completely unecessary, just use the original boolean value.</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/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2007-10-12 01:51:10 UTC (rev 934) +++ trunk/fb-contrib/samples/SPP_Sample.java 2007-10-13 03:30:42 UTC (rev 935) @@ -78,4 +78,9 @@ return s.toCharArray()[0]; return ' '; } + + public boolean testUselessTrinary(boolean b) + { + return (b ? true : false); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-12 01:51:10 UTC (rev 934) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 03:30:42 UTC (rev 935) @@ -90,7 +90,17 @@ try { stack.mergeJumps(this); - if (seen == LDC2_W) { + if (seen == ICONST_0) { + byte[] bytes = getCode().getCode(); + if (((0x00FF & bytes[lastPCs[3]]) == GOTO) + && ((0x00FF & bytes[lastPCs[2]]) == ICONST_1) + && ((0x00FF & bytes[lastPCs[1]]) == IFEQ)) { + bugReporter.reportBug(new BugInstance(this, "SPP_USELESS_TRINARY", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } else if (seen == LDC2_W) { Object con = getConstantRefOperand(); if (con instanceof ConstantDouble) { double d = ((ConstantDouble) con).getBytes(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |