[Fb-contrib-commit] SF.net SVN: fb-contrib: [773] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2007-01-05 06:22:56
|
Revision: 773 http://svn.sourceforge.net/fb-contrib/?rev=773&view=rev Author: dbrosius Date: 2007-01-04 22:22:56 -0800 (Thu, 04 Jan 2007) Log Message: ----------- get back to 3.2 dev, including adding check for calling .equals(Object o) on an enum Modified Paths: -------------- trunk/fb-contrib/build.xml 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/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2007-01-05 05:42:40 UTC (rev 772) +++ trunk/fb-contrib/build.xml 2007-01-05 06:22:56 UTC (rev 773) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.0.7"/> + <property name="fb-contrib.version" value="3.1.0"/> <target name="clean" description="removes all generated collateral"> <delete dir="${classes.dir}"/> Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-01-05 05:42:40 UTC (rev 772) +++ trunk/fb-contrib/etc/findbugs.xml 2007-01-05 06:22:56 UTC (rev 773) @@ -252,28 +252,23 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparatorReturnValues" speed="fast" - reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" - disabled="true" /> + 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" - disabled="true" /> + 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" /> <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" - reports="BAS_BLOATED_ASSIGNMENT_SCOPE" - disabled="true" /> + reports="BAS_BLOATED_ASSIGNMENT_SCOPE" /> <Detector class="com.mebigfatguy.fbcontrib.detect.SpoiledChildInterfaceImplementor" speed="fast" - reports="SCI_SPOILED_CHILD_INTERFACE_IMPLEMENTOR" - disabled="true" /> + reports="SCI_SPOILED_CHILD_INTERFACE_IMPLEMENTOR" /> <Detector class="com.mebigfatguy.fbcontrib.detect.DeletingWhileIterating" speed="fast" - reports="DWI_DELETING_WHILE_ITERATING" - disabled="true" /> + reports="DWI_DELETING_WHILE_ITERATING" /> <!-- BugPattern --> @@ -348,6 +343,7 @@ <BugPattern abbrev="SPP" type="SPP_USE_ISNAN" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_USE_BIGDECIMAL_STRING_CTOR" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_STRINGBUFFER_WITH_EMPTY_STRING" category="PERFORMANCE" experimental="true" /> + <BugPattern abbrev="SPP" type="SPP_EQUALS_ON_ENUM" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="BAS" type="BAS_BLOATED_ASSIGNMENT_SCOPE" category="PERFORMANCE" experimental="true" /> <BugPattern abbrev="SCII" type="SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR" category="STYLE" experimental="true" /> <BugPattern abbrev="DWI" type="DWI_DELETING_WHILE_ITERATING" category="CORRECTNESS" experimental="true" /> Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-01-05 05:42:40 UTC (rev 772) +++ trunk/fb-contrib/etc/messages.xml 2007-01-05 06:22:56 UTC (rev 773) @@ -1640,6 +1640,18 @@ </Details> </BugPattern> + <BugPattern type="SPP_EQUALS_ON_ENUM"> + <ShortDescription>Method calls equals on an enum instance</ShortDescription> + <LongDescription>Method {1} calls equals on an enum instance</LongDescription> + <Details> + <![CDATA[ + <p>This method calls the equals(Object) method on an enum instance. Since enums values are singletons, + you can use == to safely compare two enum values. In fact, the implementation for Enum.equals does just + that.</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-01-05 05:42:40 UTC (rev 772) +++ trunk/fb-contrib/samples/SPP_Sample.java 2007-01-05 06:22:56 UTC (rev 773) @@ -6,6 +6,8 @@ private static final double pi = 3.14; private static final double e = 2.72; + static enum Flap { Smack, Jack }; + public void testSPPBitSet(BitSet b) { b.set(-1); @@ -54,4 +56,10 @@ { StringBuffer sb = new StringBuffer(""); } + + public void equalsOnEnum(Flap f) + { + if (f.equals(Flap.Jack)) + System.out.println("Flap Jacks"); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-01-05 05:42:40 UTC (rev 772) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-01-05 06:22:56 UTC (rev 773) @@ -18,8 +18,10 @@ */ package com.mebigfatguy.fbcontrib.detect; +import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.ConstantDouble; +import org.apache.bcel.classfile.JavaClass; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; @@ -167,6 +169,18 @@ } } } + } else if ("equals(Ljava/lang/Object;)Z".equals(methodName + getSigConstantOperand())) { + try { + JavaClass cls = Repository.lookupClass(className); + if (cls.isEnum()) { + bugReporter.reportBug(new BugInstance(this, "SPP_EQUALS_ON_ENUM", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } } } 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. |