[Fb-contrib-commit] SF.net SVN: fb-contrib: [685] trunk/fb-contrib
Brought to you by:
dbrosius
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. |