fb-contrib-commit Mailing List for fb-contrib (Page 47)
Brought to you by:
dbrosius
You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(56) |
Oct
(60) |
Nov
(58) |
Dec
(89) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(66) |
Feb
(55) |
Mar
(85) |
Apr
(115) |
May
(35) |
Jun
(28) |
Jul
(3) |
Aug
(48) |
Sep
(37) |
Oct
(22) |
Nov
(14) |
Dec
(66) |
2007 |
Jan
(45) |
Feb
(63) |
Mar
(10) |
Apr
(1) |
May
(1) |
Jun
(12) |
Jul
|
Aug
|
Sep
(25) |
Oct
(21) |
Nov
(39) |
Dec
|
2008 |
Jan
(7) |
Feb
|
Mar
(26) |
Apr
(5) |
May
(2) |
Jun
(32) |
Jul
(9) |
Aug
(10) |
Sep
|
Oct
(3) |
Nov
(1) |
Dec
|
2009 |
Jan
(10) |
Feb
(31) |
Mar
(32) |
Apr
(35) |
May
(25) |
Jun
|
Jul
(31) |
Aug
(10) |
Sep
(95) |
Oct
(35) |
Nov
(10) |
Dec
(34) |
2010 |
Jan
(90) |
Feb
(4) |
Mar
(7) |
Apr
(20) |
May
(20) |
Jun
(13) |
Jul
(7) |
Aug
(18) |
Sep
(25) |
Oct
(4) |
Nov
(16) |
Dec
(2) |
2011 |
Jan
(1) |
Feb
|
Mar
(11) |
Apr
(3) |
May
(2) |
Jun
(26) |
Jul
(10) |
Aug
(2) |
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(1) |
2012 |
Jan
(3) |
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(14) |
Nov
(3) |
Dec
(4) |
2013 |
Jan
(3) |
Feb
(2) |
Mar
(1) |
Apr
(4) |
May
|
Jun
(1) |
Jul
(3) |
Aug
|
Sep
|
Oct
(4) |
Nov
(3) |
Dec
(3) |
2014 |
Jan
(4) |
Feb
(2) |
Mar
(4) |
Apr
(1) |
May
(2) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(4) |
Jun
|
Jul
|
Aug
(3) |
Sep
|
Oct
|
Nov
(3) |
Dec
(3) |
2016 |
Jan
(2) |
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
(1) |
Aug
(2) |
Sep
(4) |
Oct
(2) |
Nov
(7) |
Dec
|
2017 |
Jan
(1) |
Feb
|
Mar
(4) |
Apr
(5) |
May
(2) |
Jun
|
Jul
(2) |
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
(3) |
2018 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
(5) |
Jun
(2) |
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <dbr...@us...> - 2006-11-19 05:18:32
|
Revision: 691 http://svn.sourceforge.net/fb-contrib/?rev=691&view=rev Author: dbrosius Date: 2006-11-18 21:18:32 -0800 (Sat, 18 Nov 2006) Log Message: ----------- add non Math.constants to 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 2006-11-19 04:36:12 UTC (rev 690) +++ trunk/fb-contrib/etc/findbugs.xml 2006-11-19 05:18:32 UTC (rev 691) @@ -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"/> + reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT"/> <!-- BugPattern --> @@ -326,5 +326,6 @@ <BugPattern abbrev="SPP" type="SPP_NEGATIVE_BITSET_ITEM" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_INTERN_ON_CONSTANT" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_NO_CHAR_SB_CTOR" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="SPP" type="SPP_USE_MATH_CONSTANT" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-11-19 04:36:12 UTC (rev 690) +++ trunk/fb-contrib/etc/messages.xml 2006-11-19 05:18:32 UTC (rev 691) @@ -1551,6 +1551,17 @@ </Details> </BugPattern> + <BugPattern type="SPP_USE_MATH_CONSTANT"> + <ShortDescription>Method uses non standard math constant</ShortDescription> + <LongDescription>Method {1} uses non standard math constant</LongDescription> + <Details> + <![CDATA[ + <p>This method defines its own version of <b>PI</b> or <b>e</b> and the value is not as precise as the + one defined in the constants Math.PI or Math.E. Use these constants instead.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2006-11-19 04:36:12 UTC (rev 690) +++ trunk/fb-contrib/samples/SPP_Sample.java 2006-11-19 05:18:32 UTC (rev 691) @@ -2,7 +2,9 @@ public class SPP_Sample { - + private static final double pi = 3.14; + private static final double e = 2.72; + public void testSPPBitSet(BitSet b) { b.set(-1); @@ -19,4 +21,9 @@ sb.append("ictory"); return sb.toString(); } + + public double area(double radius) + { + return pi * radius * radius; + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-11-19 04:36:12 UTC (rev 690) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-11-19 05:18:32 UTC (rev 691) @@ -19,6 +19,7 @@ package com.mebigfatguy.fbcontrib.detect; import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.ConstantDouble; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; @@ -72,7 +73,22 @@ try { stack.mergeJumps(this); - if (seen == INVOKEVIRTUAL) { + if (seen == LDC2_W) { + Object con = getConstantRefOperand(); + if (con instanceof ConstantDouble) { + double d = ((ConstantDouble) con).getBytes(); + double piDelta = Math.abs(d - Math.PI); + double eDelta = Math.abs(d - Math.E); + + if (((piDelta > 0.0) && (piDelta < 0.002)) + || ((eDelta > 0.0) && (eDelta < 0.002))) { + bugReporter.reportBug(new BugInstance(this, "SPP_USE_MATH_CONSTANT", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } else if (seen == INVOKEVIRTUAL) { String className = getClassConstantOperand(); String methodName = getNameConstantOperand(); if ("java/util/BitSet".equals(className)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-11-19 04:36:13
|
Revision: 690 http://svn.sourceforge.net/fb-contrib/?rev=690&view=rev Author: dbrosius Date: 2006-11-18 20:36:12 -0800 (Sat, 18 Nov 2006) Log Message: ----------- spilleng Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-11-19 04:33:43 UTC (rev 689) +++ trunk/fb-contrib/etc/messages.xml 2006-11-19 04:36:12 UTC (rev 690) @@ -1540,7 +1540,7 @@ <BugPattern type="SPP_NO_CHAR_SB_CTOR"> <ShortDescription>Method passes character to StringBuffer or StringBuilder integer constructor</ShortDescription> - <LongDescription>Method {1} passes character to StringBuffer or StringBuilder integer cosntructor</LongDescription> + <LongDescription>Method {1} passes character to StringBuffer or StringBuilder integer constructor</LongDescription> <Details> <![CDATA[ <p>This method constructs a StringBuffer or a StringBuilder using the constructor that takes an integer, but This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-11-19 04:33:47
|
Revision: 689 http://svn.sourceforge.net/fb-contrib/?rev=689&view=rev Author: dbrosius Date: 2006-11-18 20:33:43 -0800 (Sat, 18 Nov 2006) Log Message: ----------- comment out sb Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-11-19 03:58:19 UTC (rev 688) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-11-19 04:33:43 UTC (rev 689) @@ -115,10 +115,10 @@ String signature = getSigConstantOperand(); if ("(I)V".equals(signature)) { if (lastOpcode == BIPUSH) { - bugReporter.reportBug(new BugInstance(this, "SPP_NO_CHAR_SB_CTOR", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + //bugReporter.reportBug(new BugInstance(this, "SPP_NO_CHAR_SB_CTOR", NORMAL_PRIORITY) + // .addClass(this) + // .addMethod(this) + // .addSourceLine(this)); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-11-19 03:58:21
|
Revision: 688 http://svn.sourceforge.net/fb-contrib/?rev=688&view=rev Author: dbrosius Date: 2006-11-18 19:58:19 -0800 (Sat, 18 Nov 2006) Log Message: ----------- doc SPP Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2006-11-19 03:56:31 UTC (rev 687) +++ trunk/fb-contrib/htdocs/index.html 2006-11-19 03:58:19 UTC (rev 688) @@ -56,6 +56,8 @@ Looks for classes that implement Comparator or Comparable, and whose compare or compareTo methods return constant values only, but that don't represent the three possible choices (a negative number, 0, and a positive number).</li> + <li><b>[SPP] Sillyness Pot Pourri</b><br/> + Looks for various small problems that don't fall into any particular category.</li> </ul> </div> <hr/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-11-19 03:56:32
|
Revision: 687 http://svn.sourceforge.net/fb-contrib/?rev=687&view=rev Author: dbrosius Date: 2006-11-18 19:56:31 -0800 (Sat, 18 Nov 2006) Log Message: ----------- add StringBuffer(char) to 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 2006-11-19 03:38:28 UTC (rev 686) +++ trunk/fb-contrib/etc/findbugs.xml 2006-11-19 03:56:31 UTC (rev 687) @@ -256,7 +256,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri" speed="fast" - reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT"/> + reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR"/> <!-- BugPattern --> @@ -325,5 +325,6 @@ <BugPattern abbrev="SCRV" type="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_NEGATIVE_BITSET_ITEM" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_INTERN_ON_CONSTANT" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="SPP" type="SPP_NO_CHAR_SB_CTOR" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-11-19 03:38:28 UTC (rev 686) +++ trunk/fb-contrib/etc/messages.xml 2006-11-19 03:56:31 UTC (rev 687) @@ -1538,6 +1538,19 @@ </Details> </BugPattern> + <BugPattern type="SPP_NO_CHAR_SB_CTOR"> + <ShortDescription>Method passes character to StringBuffer or StringBuilder integer constructor</ShortDescription> + <LongDescription>Method {1} passes character to StringBuffer or StringBuilder integer cosntructor</LongDescription> + <Details> + <![CDATA[ + <p>This method constructs a StringBuffer or a StringBuilder using the constructor that takes an integer, but + passes a character instead. It is probable that the author assumed that character would be appended to the + StringBuffer/Builder, but instead the integer value of the character is used as an initial size for the buffer. + </p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2006-11-19 03:38:28 UTC (rev 686) +++ trunk/fb-contrib/samples/SPP_Sample.java 2006-11-19 03:56:31 UTC (rev 687) @@ -12,5 +12,11 @@ { return "FOO".intern(); //and yes i've seen this! } - + + public String testSBWithChars() + { + StringBuffer sb = new StringBuffer('v'); + sb.append("ictory"); + return sb.toString(); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-11-19 03:38:28 UTC (rev 686) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-11-19 03:56:31 UTC (rev 687) @@ -33,6 +33,7 @@ { private BugReporter bugReporter; private OpcodeStack stack; + private int lastOpcode; /** * constructs a SPP detector given the reporter to report bugs on @@ -58,6 +59,7 @@ */ public void visitCode(Code obj) { stack.resetForMethodEntry(this); + lastOpcode = -1; super.visitCode(obj); } @@ -104,10 +106,28 @@ } } } + } else if (seen == INVOKESPECIAL) { + String className = getClassConstantOperand(); + if ("java/lang/StringBuffer".equals(className) + || "java/lang/StringBuilder".equals(className)) { + String methodName = getNameConstantOperand(); + if ("<init>".equals(methodName)) { + String signature = getSigConstantOperand(); + if ("(I)V".equals(signature)) { + if (lastOpcode == BIPUSH) { + bugReporter.reportBug(new BugInstance(this, "SPP_NO_CHAR_SB_CTOR", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + } } } finally { stack.sawOpcode(this, seen); + lastOpcode = seen; } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-11-19 03:38:31
|
Revision: 686 http://svn.sourceforge.net/fb-contrib/?rev=686&view=rev Author: dbrosius Date: 2006-11-18 19:38:28 -0800 (Sat, 18 Nov 2006) Log Message: ----------- add Constant string interning to 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 2006-11-19 03:16:44 UTC (rev 685) +++ trunk/fb-contrib/etc/findbugs.xml 2006-11-19 03:38:28 UTC (rev 686) @@ -256,7 +256,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri" speed="fast" - reports="SPP_NEGATIVE_BITSET_ITEM"/> + reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT"/> <!-- BugPattern --> @@ -324,5 +324,6 @@ <BugPattern abbrev="PIS" type="PIS_POSSIBLE_INCOMPLETE_SERIALIZATION" category="CORRECTNESS" /> <BugPattern abbrev="SCRV" type="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_NEGATIVE_BITSET_ITEM" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="SPP" type="SPP_INTERN_ON_CONSTANT" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-11-19 03:16:44 UTC (rev 685) +++ trunk/fb-contrib/etc/messages.xml 2006-11-19 03:38:28 UTC (rev 686) @@ -1527,6 +1527,17 @@ </Details> </BugPattern> + <BugPattern type="SPP_INTERN_ON_CONSTANT"> + <ShortDescription>Method calls intern on a string constant</ShortDescription> + <LongDescription>Method {1} calls intern on a string constant</LongDescription> + <Details> + <![CDATA[ + <p>This method calls intern on a constant string. As constant strings are already interned, this call + is superfluous</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2006-11-19 03:16:44 UTC (rev 685) +++ trunk/fb-contrib/samples/SPP_Sample.java 2006-11-19 03:38:28 UTC (rev 686) @@ -2,9 +2,15 @@ public class SPP_Sample { + public void testSPPBitSet(BitSet b) { b.set(-1); } + + public String testSPPIntern() + { + return "FOO".intern(); //and yes i've seen this! + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-11-19 03:16:44 UTC (rev 685) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-11-19 03:38:28 UTC (rev 686) @@ -33,6 +33,7 @@ { private BugReporter bugReporter; private OpcodeStack stack; + /** * constructs a SPP detector given the reporter to report bugs on * @param bugReporter the sync of bug reports @@ -71,8 +72,8 @@ if (seen == INVOKEVIRTUAL) { String className = getClassConstantOperand(); + String methodName = getNameConstantOperand(); if ("java/util/BitSet".equals(className)) { - String methodName = getNameConstantOperand(); if ("clear".equals(methodName) || "flip".equals(methodName) || "get".equals(methodName) @@ -90,6 +91,18 @@ } } } + } else if ("java/lang/String".equals(className)) { + if ("intern".equals(methodName)) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + if (item.getConstant() != null) { + bugReporter.reportBug(new BugInstance(this, "SPP_INTERN_ON_CONSTANT", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-11-19 03:16:45
|
Revision: 685 http://svn.sourceforge.net/fb-contrib/?rev=685&view=rev Author: dbrosius Date: 2006-11-18 19:16:44 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Initial checkin, new SPP detector Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- 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 2006-10-29 05:27:40 UTC (rev 684) +++ trunk/fb-contrib/etc/findbugs.xml 2006-11-19 03:16:44 UTC (rev 685) @@ -254,6 +254,10 @@ speed="fast" reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES"/> + <Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri" + speed="fast" + reports="SPP_NEGATIVE_BITSET_ITEM"/> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -319,4 +323,6 @@ <BugPattern abbrev="URV" type="URV_INHERITED_METHOD_WITH_RELATED_TYPES" category="STYLE" /> <BugPattern abbrev="PIS" type="PIS_POSSIBLE_INCOMPLETE_SERIALIZATION" category="CORRECTNESS" /> <BugPattern abbrev="SCRV" type="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="SPP" type="SPP_NEGATIVE_BITSET_ITEM" category="CORRECTNESS" experimental="true" /> + </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-10-29 05:27:40 UTC (rev 684) +++ trunk/fb-contrib/etc/messages.xml 2006-11-19 03:16:44 UTC (rev 685) @@ -686,6 +686,14 @@ </Details> </Detector> + <Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri"> + <Details> + <![CDATA[ + <p>looks for a potpourri of small problems that do not fit into a common pattern.</p> + ]]> + </Details> + </Detector> + <!-- BugPattern --> <BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING"> @@ -1508,6 +1516,17 @@ </Details> </BugPattern> + <BugPattern type="SPP_NEGATIVE_BITSET_ITEM"> + <ShortDescription>Method passes a negative number as a bit to a BitSet which isn't supported</ShortDescription> + <LongDescription>Method {1} passes a negative number as a bit to a BitSet which isn't supported</LongDescription> + <Details> + <![CDATA[ + <p>This method passes a constant negative value as a bit position to a java.util.BitSet. The BitSet class + doesn't support negative values, and thus this method call will not work as expected.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -1566,4 +1585,6 @@ <BugCode abbrev="URV">Unrelated Return Values</BugCode> <BugCode abbrev="PIS">Possible Incomplete Serialization</BugCode> <BugCode abbrev="SCRV">Suspicious Comparator Return Values</BugCode> + <BugCode abbrev="SPP">Sillyness Pot Pourri</BugCode> + </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java (rev 0) +++ trunk/fb-contrib/samples/SPP_Sample.java 2006-11-19 03:16:44 UTC (rev 685) @@ -0,0 +1,10 @@ +import java.util.BitSet; + +public class SPP_Sample +{ + public void testSPPBitSet(BitSet b) + { + b.set(-1); + } + +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-11-19 03:16:44 UTC (rev 685) @@ -0,0 +1,100 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005-2006 Dave Brosius + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package com.mebigfatguy.fbcontrib.detect; + +import org.apache.bcel.classfile.Code; + +import edu.umd.cs.findbugs.BugInstance; +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.OpcodeStack; +import edu.umd.cs.findbugs.ba.ClassContext; + +/** + * looks for silly bugs that are simple but do not fit into one large pattern. + */ +public class SillynessPotPourri extends BytecodeScanningDetector +{ + private BugReporter bugReporter; + private OpcodeStack stack; + /** + * constructs a SPP detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ + public SillynessPotPourri(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + public void visitClassContext(ClassContext classContext) { + try { + stack = new OpcodeStack(); + super.visitClassContext(classContext); + } finally { + stack = null; + } + } + + /** + * implements the visitor to reset the opcode stack + * + * @param obj the context object for the currently parsed Code + */ + public void visitCode(Code obj) { + stack.resetForMethodEntry(this); + super.visitCode(obj); + } + + /** + * implements the visitor to look for various silly bugs + * + * @param seen the opcode of the currently parsed instruction + */ + public void sawOpcode(int seen) { + try { + stack.mergeJumps(this); + + if (seen == INVOKEVIRTUAL) { + String className = getClassConstantOperand(); + if ("java/util/BitSet".equals(className)) { + String methodName = getNameConstantOperand(); + if ("clear".equals(methodName) + || "flip".equals(methodName) + || "get".equals(methodName) + || "set".equals(methodName)) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + Object o =item.getConstant(); + if (o instanceof Integer) { + if (((Integer) o).intValue() < 0) { + bugReporter.reportBug(new BugInstance(this, "SPP_NEGATIVE_BITSET_ITEM", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + } + } + } + + } finally { + stack.sawOpcode(this, seen); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-29 05:27:45
|
Revision: 684 http://svn.sourceforge.net/fb-contrib/?rev=684&view=rev Author: dbrosius Date: 2006-10-28 22:27:40 -0700 (Sat, 28 Oct 2006) Log Message: ----------- grammar Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2006-10-29 05:23:55 UTC (rev 683) +++ trunk/fb-contrib/htdocs/index.html 2006-10-29 05:27:40 UTC (rev 684) @@ -53,8 +53,8 @@ <div id="svn" style="display:block;"> <ul> <li><b>[SCRV] Suspicious Comparator Return Values</b><br/> - Looks for class that implement Comparator or Comparable, and whose compare or compareTo - methods return constant values only, but that don't represent the three possible choice + Looks for classes that implement Comparator or Comparable, and whose compare or compareTo + methods return constant values only, but that don't represent the three possible choices (a negative number, 0, and a positive number).</li> </ul> </div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-29 05:24:03
|
Revision: 683 http://svn.sourceforge.net/fb-contrib/?rev=683&view=rev Author: dbrosius Date: 2006-10-28 22:23:55 -0700 (Sat, 28 Oct 2006) Log Message: ----------- doc SCRV Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2006-10-29 00:48:19 UTC (rev 682) +++ trunk/fb-contrib/htdocs/index.html 2006-10-29 05:23:55 UTC (rev 683) @@ -48,14 +48,20 @@ <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>[SCRV] Suspicious Comparator Return Values</b><br/> + Looks for class that implement Comparator or Comparable, and whose compare or compareTo + methods return constant values only, but that don't represent the three possible choice + (a negative number, 0, and a positive number).</li> + </ul> </div> <hr/> - <img id="v3_0_0_image" src="flip2.gif" onClick="toggleBlock('v3_0_0', 'svn_image');" align="top"/> + <img id="v3_0_0_image" src="flip1.gif" onClick="toggleBlock('v3_0_0', 'svn_image');" align="top"/> Detectors added in v3.0.0<br/> - <div id="svn" style="display:block;"> + <div id="svn" style="display:none;"> <ul> <li><b>[LEST] Lost Exception Stack Trace</b><br/> Looks for methods that catch exceptions, and rethrow another exception without encapsulating This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-29 00:48:25
|
Revision: 682 http://svn.sourceforge.net/fb-contrib/?rev=682&view=rev Author: dbrosius Date: 2006-10-28 17:48:19 -0700 (Sat, 28 Oct 2006) Log Message: ----------- fix signatures Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2006-10-29 00:40:58 UTC (rev 681) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2006-10-29 00:48:19 UTC (rev 682) @@ -24,8 +24,8 @@ private static Map<JavaClass, String> compareClasses = new HashMap<JavaClass, String>(); static { try { - compareClasses.put(Repository.lookupClass("java/lang/Comparable"), "compare:2:I");; - compareClasses.put(Repository.lookupClass("java/util/Comparator"), "compareTo:1:I"); + compareClasses.put(Repository.lookupClass("java/lang/Comparable"), "compareTo:1:I");; + compareClasses.put(Repository.lookupClass("java/util/Comparator"), "compare:2:I"); } catch (ClassNotFoundException cnfe) { } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-29 00:41:05
|
Revision: 681 http://svn.sourceforge.net/fb-contrib/?rev=681&view=rev Author: dbrosius Date: 2006-10-28 17:40:58 -0700 (Sat, 28 Oct 2006) Log Message: ----------- fix comparator class specification Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2006-10-29 00:08:39 UTC (rev 680) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2006-10-29 00:40:58 UTC (rev 681) @@ -25,7 +25,7 @@ static { try { compareClasses.put(Repository.lookupClass("java/lang/Comparable"), "compare:2:I");; - compareClasses.put(Repository.lookupClass("java.lang/Comparator"), "compareTo:1:I"); + compareClasses.put(Repository.lookupClass("java/util/Comparator"), "compareTo:1:I"); } catch (ClassNotFoundException cnfe) { } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-29 00:08:42
|
Revision: 680 http://svn.sourceforge.net/fb-contrib/?rev=680&view=rev Author: dbrosius Date: 2006-10-28 17:08:39 -0700 (Sat, 28 Oct 2006) Log Message: ----------- fix name Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-10-29 00:07:46 UTC (rev 679) +++ trunk/fb-contrib/etc/messages.xml 2006-10-29 00:08:39 UTC (rev 680) @@ -676,7 +676,7 @@ </Details> </Detector> - <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparator"> + <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparatorReturnValues"> <Details> <![CDATA[ <p>looks for class that implement Comparator or Comparable, and whose compare or compareTo This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-29 00:07:51
|
Revision: 679 http://svn.sourceforge.net/fb-contrib/?rev=679&view=rev Author: dbrosius Date: 2006-10-28 17:07:46 -0700 (Sat, 28 Oct 2006) Log Message: ----------- fix name Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-10-28 18:29:46 UTC (rev 678) +++ trunk/fb-contrib/etc/findbugs.xml 2006-10-29 00:07:46 UTC (rev 679) @@ -250,7 +250,7 @@ speed="fast" reports="PIS_POSSIBLE_INCOMPLETE_SERIALIZATION" /> - <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparator" + <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparatorReturnValues" speed="fast" reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-28 18:33:16
|
Revision: 678 http://svn.sourceforge.net/fb-contrib/?rev=678&view=rev Author: dbrosius Date: 2006-10-28 11:29:46 -0700 (Sat, 28 Oct 2006) Log Message: ----------- adjust SC to SCRV Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Removed Paths: ------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparator.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-10-28 18:21:35 UTC (rev 677) +++ trunk/fb-contrib/etc/findbugs.xml 2006-10-28 18:29:46 UTC (rev 678) @@ -252,7 +252,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparator" speed="fast" - reports="SC_SUSPICIOUS_COMPARATOR"/> + reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES"/> <!-- BugPattern --> @@ -318,5 +318,5 @@ <BugPattern abbrev="URV" type="URV_CHANGE_RETURN_TYPE" category="STYLE" /> <BugPattern abbrev="URV" type="URV_INHERITED_METHOD_WITH_RELATED_TYPES" category="STYLE" /> <BugPattern abbrev="PIS" type="PIS_POSSIBLE_INCOMPLETE_SERIALIZATION" category="CORRECTNESS" /> - <BugPattern abbrev="SC" type="SC_SUSPICIOUS_COMPARATOR" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="SCRV" type="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-10-28 18:21:35 UTC (rev 677) +++ trunk/fb-contrib/etc/messages.xml 2006-10-28 18:29:46 UTC (rev 678) @@ -1496,7 +1496,7 @@ </Details> </BugPattern> - <BugPattern type="SC_SUSPICIOUS_COMPARATOR"> + <BugPattern type="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES"> <ShortDescription>Comparator method doesn't seem to return all ordering values</ShortDescription> <LongDescription>Comparator method {1} doesn't seem to return all ordering values</LongDescription> <Details> @@ -1565,5 +1565,5 @@ <BugCode abbrev="TR">Tail Recursion</BugCode> <BugCode abbrev="URV">Unrelated Return Values</BugCode> <BugCode abbrev="PIS">Possible Incomplete Serialization</BugCode> - <BugCode abbrev="SC">Suspicious Comparator</BugCode> + <BugCode abbrev="SCRV">Suspicious Comparator Return Values</BugCode> </MessageCollection> \ No newline at end of file Deleted: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparator.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparator.java 2006-10-28 18:21:35 UTC (rev 677) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparator.java 2006-10-28 18:29:46 UTC (rev 678) @@ -1,120 +0,0 @@ -package com.mebigfatguy.fbcontrib.detect; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.bcel.Repository; -import org.apache.bcel.classfile.Code; -import org.apache.bcel.classfile.JavaClass; -import org.apache.bcel.generic.Type; - -import edu.umd.cs.findbugs.BugInstance; -import edu.umd.cs.findbugs.BugReporter; -import edu.umd.cs.findbugs.BytecodeScanningDetector; -import edu.umd.cs.findbugs.OpcodeStack; -import edu.umd.cs.findbugs.ba.ClassContext; - -/** - * looks for class that implement Comparator or Comparable, and whose compare or compareTo - * methods return constant values only, but that don't represent the three possible choice - * (a negative number, 0, and a positive number). - */ -public class SuspiciousComparator extends BytecodeScanningDetector -{ - private static Map<JavaClass, String> compareClasses = new HashMap<JavaClass, String>(); - static { - try { - compareClasses.put(Repository.lookupClass("java/lang/Comparable"), "compare:2:I");; - compareClasses.put(Repository.lookupClass("java.lang/Comparator"), "compareTo:1:I"); - } catch (ClassNotFoundException cnfe) { - } - } - - private OpcodeStack stack; - private BugReporter bugReporter; - private String[] methodInfo; - private boolean indeterminate; - private boolean seenNegative; - private boolean seenPositive; - private boolean seenZero; - - - /** - * constructs a DRE detector given the reporter to report bugs on - * @param bugReporter the sync of bug reports - */ - public SuspiciousComparator(BugReporter bugReporter) { - this.bugReporter = bugReporter; - } - - public void visitClassContext(ClassContext classContext) { - try { - JavaClass cls = classContext.getJavaClass(); - for (Map.Entry<JavaClass, String> entry : compareClasses.entrySet()) { - if (cls.implementationOf(entry.getKey())) { - methodInfo = entry.getValue().split(":"); - stack = new OpcodeStack(); - super.visitClassContext(classContext); - break; - } - } - } catch (ClassNotFoundException cnfe) { - bugReporter.reportMissingClass(cnfe); - } finally { - methodInfo = null; - stack = null; - } - } - - public void visitCode(Code obj) { - String methodName = getMethodName(); - String methodSig = getMethodSig(); - if (methodName.equals(methodInfo[0]) - && methodSig.endsWith(methodInfo[2]) - && (Type.getArgumentTypes(methodSig).length == Integer.valueOf(methodInfo[1]))) { - stack.resetForMethodEntry(this); - indeterminate = false; - seenNegative = false; - seenPositive = false; - seenZero = false; - super.visitCode(obj); - if (!indeterminate) { - boolean seenAll = seenNegative & seenPositive & seenZero; - if (!seenAll) { - bugReporter.reportBug(new BugInstance(this, "SC_SUSPICIOUS_COMPARATOR", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this, 0)); - } - } - } - } - - public void sawOpcode(int seen) { - try { - if (indeterminate) - return; - - if (seen == IRETURN) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item item = stack.getStackItem(0); - Integer returnValue = (Integer)item.getConstant(); - if (returnValue == null) - indeterminate = true; - else { - int v = returnValue.intValue(); - if (v < 0) - seenNegative = true; - else if (v > 0) - seenPositive = true; - else - seenZero = true; - } - } else - indeterminate = true; - } - } finally { - stack.sawOpcode(this, seen); - } - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-28 18:22:56
|
Revision: 677 http://svn.sourceforge.net/fb-contrib/?rev=677&view=rev Author: dbrosius Date: 2006-10-28 11:21:35 -0700 (Sat, 28 Oct 2006) Log Message: ----------- change to SCRV Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2006-10-28 18:15:56 UTC (rev 676) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2006-10-28 18:21:35 UTC (rev 677) @@ -81,7 +81,7 @@ if (!indeterminate) { boolean seenAll = seenNegative & seenPositive & seenZero; if (!seenAll) { - bugReporter.reportBug(new BugInstance(this, "SC_SUSPICIOUS_COMPARATOR", NORMAL_PRIORITY) + bugReporter.reportBug(new BugInstance(this, "SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES", NORMAL_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(this, 0)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-28 18:17:13
|
Revision: 676 http://svn.sourceforge.net/fb-contrib/?rev=676&view=rev Author: dbrosius Date: 2006-10-28 11:15:56 -0700 (Sat, 28 Oct 2006) Log Message: ----------- initial checkin SC detector Added Paths: ----------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2006-10-28 18:15:56 UTC (rev 676) @@ -0,0 +1,120 @@ +package com.mebigfatguy.fbcontrib.detect; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.bcel.Repository; +import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.generic.Type; + +import edu.umd.cs.findbugs.BugInstance; +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.OpcodeStack; +import edu.umd.cs.findbugs.ba.ClassContext; + +/** + * looks for class that implement Comparator or Comparable, and whose compare or compareTo + * methods return constant values only, but that don't represent the three possible choice + * (a negative number, 0, and a positive number). + */ +public class SuspiciousComparatorReturnValues extends BytecodeScanningDetector +{ + private static Map<JavaClass, String> compareClasses = new HashMap<JavaClass, String>(); + static { + try { + compareClasses.put(Repository.lookupClass("java/lang/Comparable"), "compare:2:I");; + compareClasses.put(Repository.lookupClass("java.lang/Comparator"), "compareTo:1:I"); + } catch (ClassNotFoundException cnfe) { + } + } + + private OpcodeStack stack; + private BugReporter bugReporter; + private String[] methodInfo; + private boolean indeterminate; + private boolean seenNegative; + private boolean seenPositive; + private boolean seenZero; + + + /** + * constructs a DRE detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ + public SuspiciousComparatorReturnValues(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + public void visitClassContext(ClassContext classContext) { + try { + JavaClass cls = classContext.getJavaClass(); + for (Map.Entry<JavaClass, String> entry : compareClasses.entrySet()) { + if (cls.implementationOf(entry.getKey())) { + methodInfo = entry.getValue().split(":"); + stack = new OpcodeStack(); + super.visitClassContext(classContext); + break; + } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } finally { + methodInfo = null; + stack = null; + } + } + + public void visitCode(Code obj) { + String methodName = getMethodName(); + String methodSig = getMethodSig(); + if (methodName.equals(methodInfo[0]) + && methodSig.endsWith(methodInfo[2]) + && (Type.getArgumentTypes(methodSig).length == Integer.valueOf(methodInfo[1]))) { + stack.resetForMethodEntry(this); + indeterminate = false; + seenNegative = false; + seenPositive = false; + seenZero = false; + super.visitCode(obj); + if (!indeterminate) { + boolean seenAll = seenNegative & seenPositive & seenZero; + if (!seenAll) { + bugReporter.reportBug(new BugInstance(this, "SC_SUSPICIOUS_COMPARATOR", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this, 0)); + } + } + } + } + + public void sawOpcode(int seen) { + try { + if (indeterminate) + return; + + if (seen == IRETURN) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + Integer returnValue = (Integer)item.getConstant(); + if (returnValue == null) + indeterminate = true; + else { + int v = returnValue.intValue(); + if (v < 0) + seenNegative = true; + else if (v > 0) + seenPositive = true; + else + seenZero = true; + } + } else + indeterminate = true; + } + } finally { + stack.sawOpcode(this, seen); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-28 17:48:39
|
Revision: 675 http://svn.sourceforge.net/fb-contrib/?rev=675&view=rev Author: dbrosius Date: 2006-10-28 10:47:13 -0700 (Sat, 28 Oct 2006) Log Message: ----------- add sc to the xml files Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-10-27 05:27:56 UTC (rev 674) +++ trunk/fb-contrib/etc/findbugs.xml 2006-10-28 17:47:13 UTC (rev 675) @@ -249,6 +249,11 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.PossibleIncompleteSerialization" speed="fast" reports="PIS_POSSIBLE_INCOMPLETE_SERIALIZATION" /> + + <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparator" + speed="fast" + reports="SC_SUSPICIOUS_COMPARATOR"/> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -306,11 +311,12 @@ <BugPattern abbrev="SACM" type="SACM_STATIC_ARRAY_CREATED_IN_METHOD" category="PERFORMANCE" /> <BugPattern abbrev="PRMC" type="PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS" category="PERFORMANCE" /> <BugPattern abbrev="UTA" type="UTA_USE_TO_ARRAY" category="STYLE" /> - <BugPattern abbrev="LEST" type="LEST_LOST_EXCEPTION_STACK_TRACE" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="UCPM" type="UCPM_USE_CHARACTER_PARAMETERIZED_METHOD" category="PERFORMANCE" experimental="true" /> - <BugPattern abbrev="TR" type="TR_TAIL_RECURSION" category="PERFORMANCE" experimental="true" /> - <BugPattern abbrev="URV" type="URV_UNRELATED_RETURN_VALUES" category="STYLE" experimental="true" /> - <BugPattern abbrev="URV" type="URV_CHANGE_RETURN_TYPE" category="STYLE" experimental="true" /> - <BugPattern abbrev="URV" type="URV_INHERITED_METHOD_WITH_RELATED_TYPES" category="STYLE" experimental="true" /> - <BugPattern abbrev="PIS" type="PIS_POSSIBLE_INCOMPLETE_SERIALIZATION" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="LEST" type="LEST_LOST_EXCEPTION_STACK_TRACE" category="CORRECTNESS" /> + <BugPattern abbrev="UCPM" type="UCPM_USE_CHARACTER_PARAMETERIZED_METHOD" category="PERFORMANCE" /> + <BugPattern abbrev="TR" type="TR_TAIL_RECURSION" category="PERFORMANCE" /> + <BugPattern abbrev="URV" type="URV_UNRELATED_RETURN_VALUES" category="STYLE" /> + <BugPattern abbrev="URV" type="URV_CHANGE_RETURN_TYPE" category="STYLE" /> + <BugPattern abbrev="URV" type="URV_INHERITED_METHOD_WITH_RELATED_TYPES" category="STYLE" /> + <BugPattern abbrev="PIS" type="PIS_POSSIBLE_INCOMPLETE_SERIALIZATION" category="CORRECTNESS" /> + <BugPattern abbrev="SC" type="SC_SUSPICIOUS_COMPARATOR" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-10-27 05:27:56 UTC (rev 674) +++ trunk/fb-contrib/etc/messages.xml 2006-10-28 17:47:13 UTC (rev 675) @@ -675,6 +675,16 @@ ]]> </Details> </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparator"> + <Details> + <![CDATA[ + <p>looks for class that implement Comparator or Comparable, and whose compare or compareTo + methods return constant values only, but that don't represent the three possible choice + (a negative number, 0, and a positive number).</p> + ]]> + </Details> + </Detector> <!-- BugPattern --> @@ -1486,6 +1496,18 @@ </Details> </BugPattern> + <BugPattern type="SC_SUSPICIOUS_COMPARATOR"> + <ShortDescription>Comparator method doesn't seem to return all ordering values</ShortDescription> + <LongDescription>Comparator method {1} doesn't seem to return all ordering values</LongDescription> + <Details> + <![CDATA[ + <p>This compareTo or compare method returns constant values for to represent less than, + equals and greater than. However it does not return each type. Given that comparators + are transitive, this seems incorrect.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -1543,4 +1565,5 @@ <BugCode abbrev="TR">Tail Recursion</BugCode> <BugCode abbrev="URV">Unrelated Return Values</BugCode> <BugCode abbrev="PIS">Possible Incomplete Serialization</BugCode> + <BugCode abbrev="SC">Suspicious Comparator</BugCode> </MessageCollection> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-27 05:28:07
|
Revision: 674 http://svn.sourceforge.net/fb-contrib/?rev=674&view=rev Author: dbrosius Date: 2006-10-26 22:27:56 -0700 (Thu, 26 Oct 2006) Log Message: ----------- Initial checkin SC detector (no xml support yet) Added Paths: ----------- trunk/fb-contrib/samples/SC_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparator.java Added: trunk/fb-contrib/samples/SC_Sample.java =================================================================== --- trunk/fb-contrib/samples/SC_Sample.java (rev 0) +++ trunk/fb-contrib/samples/SC_Sample.java 2006-10-27 05:27:56 UTC (rev 674) @@ -0,0 +1,28 @@ +import java.util.Comparator; + +public class SC_Sample +{ + public static final int T1 = 0; + public static final int T2 = 1; + + int t = 0; + class SampleComparator implements Comparator<SC_Sample> + { + public int compare(SC_Sample arg0, SC_Sample arg1) { + if (arg0.t == arg1.t) + return 0; + + return -1; + } + } + + class SampleComparable implements Comparable<SC_Sample> + { + public int compareTo(SC_Sample arg0) { + if (t == arg0.t) + return 0; + + return 1; + } + } +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparator.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparator.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparator.java 2006-10-27 05:27:56 UTC (rev 674) @@ -0,0 +1,120 @@ +package com.mebigfatguy.fbcontrib.detect; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.bcel.Repository; +import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.generic.Type; + +import edu.umd.cs.findbugs.BugInstance; +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.OpcodeStack; +import edu.umd.cs.findbugs.ba.ClassContext; + +/** + * looks for class that implement Comparator or Comparable, and whose compare or compareTo + * methods return constant values only, but that don't represent the three possible choice + * (a negative number, 0, and a positive number). + */ +public class SuspiciousComparator extends BytecodeScanningDetector +{ + private static Map<JavaClass, String> compareClasses = new HashMap<JavaClass, String>(); + static { + try { + compareClasses.put(Repository.lookupClass("java/lang/Comparable"), "compare:2:I");; + compareClasses.put(Repository.lookupClass("java.lang/Comparator"), "compareTo:1:I"); + } catch (ClassNotFoundException cnfe) { + } + } + + private OpcodeStack stack; + private BugReporter bugReporter; + private String[] methodInfo; + private boolean indeterminate; + private boolean seenNegative; + private boolean seenPositive; + private boolean seenZero; + + + /** + * constructs a DRE detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ + public SuspiciousComparator(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + public void visitClassContext(ClassContext classContext) { + try { + JavaClass cls = classContext.getJavaClass(); + for (Map.Entry<JavaClass, String> entry : compareClasses.entrySet()) { + if (cls.implementationOf(entry.getKey())) { + methodInfo = entry.getValue().split(":"); + stack = new OpcodeStack(); + super.visitClassContext(classContext); + break; + } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } finally { + methodInfo = null; + stack = null; + } + } + + public void visitCode(Code obj) { + String methodName = getMethodName(); + String methodSig = getMethodSig(); + if (methodName.equals(methodInfo[0]) + && methodSig.endsWith(methodInfo[2]) + && (Type.getArgumentTypes(methodSig).length == Integer.valueOf(methodInfo[1]))) { + stack.resetForMethodEntry(this); + indeterminate = false; + seenNegative = false; + seenPositive = false; + seenZero = false; + super.visitCode(obj); + if (!indeterminate) { + boolean seenAll = seenNegative & seenPositive & seenZero; + if (!seenAll) { + bugReporter.reportBug(new BugInstance(this, "SC_SUSPICIOUS_COMPARATOR", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this, 0)); + } + } + } + } + + public void sawOpcode(int seen) { + try { + if (indeterminate) + return; + + if (seen == IRETURN) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + Integer returnValue = (Integer)item.getConstant(); + if (returnValue == null) + indeterminate = true; + else { + int v = returnValue.intValue(); + if (v < 0) + seenNegative = true; + else if (v > 0) + seenPositive = true; + else + seenZero = true; + } + } else + indeterminate = true; + } + } finally { + stack.sawOpcode(this, seen); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-18 02:24:17
|
Revision: 673 http://svn.sourceforge.net/fb-contrib/?rev=673&view=rev Author: dbrosius Date: 2006-10-17 19:24:01 -0700 (Tue, 17 Oct 2006) Log Message: ----------- if there key collisions, then insert a MethodInfo with 0, 0 in it, so that we don't get false positives Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/Statistics.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/Statistics.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/Statistics.java 2006-10-17 23:11:45 UTC (rev 672) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/Statistics.java 2006-10-18 02:24:01 UTC (rev 673) @@ -28,7 +28,11 @@ hashCode <<= 8; hashCode |= signature.hashCode(); - methodStatistics.put(getKey(className, methodName, signature), getValue(methodInfo)); + Long key = getKey(className, methodName, signature); + if (methodStatistics.containsKey(key)) + methodStatistics.put(key, getValue(new MethodInfo())); + else + methodStatistics.put(getKey(className, methodName, signature), getValue(methodInfo)); } public MethodInfo getMethodStatistics(String className, String methodName, String signature) { @@ -58,8 +62,8 @@ private MethodInfo buildMethodInfo(Long value) { MethodInfo mi = new MethodInfo(); long v = value.longValue(); - mi.numBytes = (int)(v >> 32); - mi.numMethodCalls = (int)(v & 0x0FFFFFFFF); + mi.numBytes = (int)(v >>> 32); + mi.numMethodCalls = (int)(v & 0x7FFFFFFF); return mi; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-12 04:59:19
|
Revision: 671 http://svn.sourceforge.net/fb-contrib/?rev=671&view=rev Author: dbrosius Date: 2006-10-11 21:59:11 -0700 (Wed, 11 Oct 2006) Log Message: ----------- made a copy Added Paths: ----------- tags/v3_0_2/ Copied: tags/v3_0_2 (from rev 670, trunk) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-12 04:58:14
|
Revision: 670 http://svn.sourceforge.net/fb-contrib/?rev=670&view=rev Author: dbrosius Date: 2006-10-11 21:58:09 -0700 (Wed, 11 Oct 2006) Log Message: ----------- prepare for 3.0.2 Modified Paths: -------------- trunk/fb-contrib/build.xml Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2006-10-11 00:04:00 UTC (rev 669) +++ trunk/fb-contrib/build.xml 2006-10-12 04:58:09 UTC (rev 670) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.0.1"/> + <property name="fb-contrib.version" value="3.0.2"/> <target name="clean" description="removes all generated collateral"> <delete dir="${classes.dir}"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-11 00:04:08
|
Revision: 669 http://svn.sourceforge.net/fb-contrib/?rev=669&view=rev Author: dbrosius Date: 2006-10-10 17:04:00 -0700 (Tue, 10 Oct 2006) Log Message: ----------- the handler pc can equal the end pc Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-10-10 23:37:05 UTC (rev 668) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-10-11 00:04:00 UTC (rev 669) @@ -142,7 +142,7 @@ public CodeException[] collectExceptions(CodeException[] exceptions) { List<CodeException> filteredEx = new ArrayList<CodeException>(); for (CodeException ce : exceptions) { - if ((ce.getStartPC() < ce.getEndPC()) && (ce.getEndPC() < ce.getHandlerPC())) { + if ((ce.getStartPC() < ce.getEndPC()) && (ce.getEndPC() <= ce.getHandlerPC())) { filteredEx.add(ce); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-10 23:37:09
|
Revision: 668 http://svn.sourceforge.net/fb-contrib/?rev=668&view=rev Author: dbrosius Date: 2006-10-10 16:37:05 -0700 (Tue, 10 Oct 2006) Log Message: ----------- don't report LEST if the exception that is thrown was compiled with a jdk less than version 1.4 Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-10-10 06:01:42 UTC (rev 667) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-10-10 23:37:05 UTC (rev 668) @@ -84,8 +84,7 @@ @Override public void visitClassContext(ClassContext classContext) { try { - int majorVersion = classContext.getJavaClass().getMajor(); - if ((throwableClass != null) && (majorVersion >= Constants.MAJOR_1_4)) { + if ((throwableClass != null) && (!isPre14Class(classContext.getJavaClass()))) { stack = new OpcodeStack(); catchInfos = new HashSet<CatchInfo>(); exReg = new HashMap<Integer, Boolean>(); @@ -217,10 +216,13 @@ OpcodeStack.Item itm = stack.getStackItem(0); if ((itm.getRegisterNumber() != catchInfo.getRegister()) && (itm.getUserValue() == null)) { - bugReporter.reportBug(new BugInstance(this, "LEST_LOST_EXCEPTION_STACK_TRACE", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + if (!isPre14Class(itm.getJavaClass())) + { + bugReporter.reportBug(new BugInstance(this, "LEST_LOST_EXCEPTION_STACK_TRACE", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } it.remove(); break; } @@ -257,6 +259,16 @@ } } + /** returns whether the class in question was compiled with a jdk less than 1.4 + * + * @param exClass the class to check + * @return whether the class is compiled with a jdk less than 1.4 + */ + private boolean isPre14Class(JavaClass cls) + { + return cls.getMajor() < Constants.MAJOR_1_4; + } + private void removePreviousHandlers(int pc) { //This unnecessarily squashes some nested catch blocks, but better than false positives This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-10 06:02:05
|
Revision: 667 http://svn.sourceforge.net/fb-contrib/?rev=667&view=rev Author: dbrosius Date: 2006-10-09 23:01:42 -0700 (Mon, 09 Oct 2006) Log Message: ----------- made a copy Added Paths: ----------- tags/v3_0_1/ Copied: tags/v3_0_1 (from rev 666, ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-10 06:00:37
|
Revision: 666 http://svn.sourceforge.net/fb-contrib/?rev=666&view=rev Author: dbrosius Date: 2006-10-09 23:00:34 -0700 (Mon, 09 Oct 2006) Log Message: ----------- prepare for 3.0.1 Modified Paths: -------------- trunk/fb-contrib/build.xml Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2006-10-10 05:58:53 UTC (rev 665) +++ trunk/fb-contrib/build.xml 2006-10-10 06:00:34 UTC (rev 666) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.0.0"/> + <property name="fb-contrib.version" value="3.0.1"/> <target name="clean" description="removes all generated collateral"> <delete dir="${classes.dir}"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |