Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [957] trunk/fb-contrib (Page 4)
Brought to you by:
dbrosius
From: <dbr...@us...> - 2007-11-07 07:05:22
|
Revision: 957 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=957&view=rev Author: dbrosius Date: 2007-11-06 23:05:22 -0800 (Tue, 06 Nov 2007) Log Message: ----------- get ready for 3.4.1 Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2007-11-07 07:02:42 UTC (rev 956) +++ trunk/fb-contrib/build.xml 2007-11-07 07:05:22 UTC (rev 957) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.5.0"/> + <property name="fb-contrib.version" value="3.4.1"/> <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-11-07 07:02:42 UTC (rev 956) +++ trunk/fb-contrib/etc/findbugs.xml 2007-11-07 07:05:22 UTC (rev 957) @@ -302,7 +302,8 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.ConfusingFunctionSemantics" speed="fast" - reports="CFS_CONFUSING_FUNCTION_SEMANTICS" /> + reports="CFS_CONFUSING_FUNCTION_SEMANTICS" + hidden="true" /> <!-- BugPattern --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-11-07 07:16:32
|
Revision: 959 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=959&view=rev Author: dbrosius Date: 2007-11-06 23:16:36 -0800 (Tue, 06 Nov 2007) Log Message: ----------- go back to 3.6.0 development Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2007-11-07 07:08:48 UTC (rev 958) +++ trunk/fb-contrib/build.xml 2007-11-07 07:16:36 UTC (rev 959) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.4.1"/> + <property name="fb-contrib.version" value="3.5.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-11-07 07:08:48 UTC (rev 958) +++ trunk/fb-contrib/etc/findbugs.xml 2007-11-07 07:16:36 UTC (rev 959) @@ -302,8 +302,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.ConfusingFunctionSemantics" speed="fast" - reports="CFS_CONFUSING_FUNCTION_SEMANTICS" - hidden="true" /> + reports="CFS_CONFUSING_FUNCTION_SEMANTICS" /> <!-- BugPattern --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-11-08 06:31:34
|
Revision: 960 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=960&view=rev Author: dbrosius Date: 2007-11-07 22:31:38 -0800 (Wed, 07 Nov 2007) Log Message: ----------- add SPP_SUSPECT_STRING_TEST bug pattern 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-11-07 07:16:36 UTC (rev 959) +++ trunk/fb-contrib/etc/findbugs.xml 2007-11-08 06:31:38 UTC (rev 960) @@ -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" /> + 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" /> <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" @@ -387,6 +387,7 @@ <BugPattern abbrev="SPP" type="SPP_INVALID_BOOLEAN_NULL_CHECK" category="CORRECTNESS" /> <BugPattern abbrev="SPP" type="SPP_USE_CHARAT" category="PERFORMANCE" /> <BugPattern abbrev="SPP" type="SPP_USELESS_TRINARY" category="PERFORMANCE" /> + <BugPattern abbrev="SPP" type="SPP_SUSPECT_STRING_TEST" category="CORRECTNESS" /> <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-11-07 07:16:36 UTC (rev 959) +++ trunk/fb-contrib/etc/messages.xml 2007-11-08 06:31:38 UTC (rev 960) @@ -1895,6 +1895,18 @@ </Details> </BugPattern> + <BugPattern type="SPP_SUSPECT_STRING_TEST"> + <ShortDescription>Method treats null and normal strings differently than an empty strings</ShortDescription> + <LongDescription>Method {1} treats null and normal strings differently than an empty strings</LongDescription> + <Details> + <![CDATA[ + <p>This method tests a string, and groups null values with real strings, leaving empty strings as another + case. This might be perfectly valid, but normally, null strings and empty strings are logically handled the same, + and so this test may be flawed.</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-11-07 07:16:36 UTC (rev 959) +++ trunk/fb-contrib/samples/SPP_Sample.java 2007-11-08 06:31:38 UTC (rev 960) @@ -96,4 +96,14 @@ { return (s.length() != 0); } + + public void testSuspiciousStringTests(String s) + { + if ((s == null) || (s.length() > 0)) + System.out.println("Booya"); + if ((s == null) || (s.length() != 0)) + System.out.println("Booya"); + if ((s != null) && (s.length() == 0)) + System.out.println("Booya"); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-11-07 07:16:36 UTC (rev 959) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-11-08 06:31:38 UTC (rev 960) @@ -27,7 +27,12 @@ import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.ConstantDouble; +import org.apache.bcel.classfile.ConstantMethodref; +import org.apache.bcel.classfile.ConstantNameAndType; +import org.apache.bcel.classfile.ConstantPool; import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.LocalVariable; +import org.apache.bcel.classfile.LocalVariableTable; import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; @@ -37,6 +42,7 @@ import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.visitclass.LVTHelper; /** * looks for silly bugs that are simple but do not fit into one large pattern. @@ -49,6 +55,7 @@ private int lastOpcode; private int lastReg; private boolean lastIfEqWasBoolean; + private boolean lastLoadWasString; /** branch targets, to a set of branch instructions */ private Map<Integer, Set<Integer>> branchTargets; @@ -85,6 +92,7 @@ lastOpcode = -1; lastReg = -1; lastIfEqWasBoolean = false; + lastLoadWasString = false; Arrays.fill(lastPCs, -1); branchTargets.clear(); super.visitCode(obj); @@ -113,6 +121,34 @@ branchInsSet.add(Integer14.valueOf(getPC())); } + if ((seen == IFEQ) || (seen == IFLE) || (seen == IFNE)) { + if (lastLoadWasString && (lastPCs[0] != -1)) { + byte[] bytes = getCode().getCode(); + int loadIns = get1Byte(bytes, lastPCs[2]); + + if ((((loadIns >= ALOAD_0) && (loadIns <= ALOAD_3)) || (loadIns == ALOAD)) + && (get1Byte(bytes, lastPCs[3]) == INVOKEVIRTUAL) + && (get1Byte(bytes, lastPCs[2]) == loadIns) + && (get1Byte(bytes, lastPCs[1]) == IFNULL) + && (get1Byte(bytes, lastPCs[0]) == loadIns) + && ((loadIns != ALOAD) || (get1Byte(bytes, lastPCs[2]+1) == get1Byte(bytes, lastPCs[0]+1))) + && ((seen == IFNE) ? get2Bytes(bytes, lastPCs[1]+1) > 10 : get2Bytes(bytes, lastPCs[1]+1) == 10)) { + ConstantPool pool = getConstantPool(); + int mpoolIndex = get2Bytes(bytes, lastPCs[3]+1); + ConstantMethodref cmr = (ConstantMethodref)pool.getConstant(mpoolIndex); + int nandtIndex = cmr.getNameAndTypeIndex(); + ConstantNameAndType cnt = (ConstantNameAndType)pool.getConstant(nandtIndex); + if ("length".equals(cnt.getName(pool))) { + bugReporter.reportBug(new BugInstance(this, "SPP_SUSPECT_STRING_TEST", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + } + + if (seen == IFEQ) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); @@ -185,7 +221,7 @@ .addSourceLine(this)); } } - } else if (((seen >= ASTORE_0) && (seen < ASTORE_3)) || (seen == ASTORE)) { + } else if (((seen >= ASTORE_0) && (seen <= ASTORE_3)) || (seen == ASTORE)) { reg = RegisterUtils.getAStoreReg(this, seen); if (seen == lastOpcode) { if (reg == lastReg) { @@ -195,6 +231,15 @@ .addSourceLine(this)); } } + } else if (((seen >= ALOAD_0) && (seen <= ASTORE_3)) || (seen == ALOAD)) { + lastLoadWasString = false; + LocalVariableTable lvt = getMethod().getLocalVariableTable(); + if (lvt != null) { + LocalVariable lv = LVTHelper.getLocalVariableAtPC(lvt, RegisterUtils.getALoadReg(this, seen), getPC()); + if (lv != null) { + lastLoadWasString = "Ljava/lang/String;".equals(lv.getSignature()); + } + } } else if ((seen >= ICONST_0) && (seen <= ICONST_3)) { if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); @@ -359,4 +404,14 @@ lastPCs[3] = getPC(); } } + + private int get1Byte(byte[] bytes, int offset) + { + return (0x00FF & bytes[offset]); + } + + private int get2Bytes(byte[] bytes, int offset) + { + return (0x0000FFFF & (bytes[offset] << 8)) | (0x00FF & bytes[offset+1]); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-11-08 23:03:52
|
Revision: 961 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=961&view=rev Author: dbrosius Date: 2007-11-08 15:03:56 -0800 (Thu, 08 Nov 2007) Log Message: ----------- remove fps Modified Paths: -------------- trunk/fb-contrib/samples/SPP_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2007-11-08 06:31:38 UTC (rev 960) +++ trunk/fb-contrib/samples/SPP_Sample.java 2007-11-08 23:03:56 UTC (rev 961) @@ -106,4 +106,10 @@ if ((s != null) && (s.length() == 0)) System.out.println("Booya"); } + + public void testFPSST(String s) + { + if ((s == null) || (s.length() == 0)) + System.out.println("Booya"); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-11-08 06:31:38 UTC (rev 960) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-11-08 23:03:56 UTC (rev 961) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or @@ -49,7 +49,7 @@ */ public class SillynessPotPourri extends BytecodeScanningDetector { - private BugReporter bugReporter; + private final BugReporter bugReporter; private OpcodeStack stack; private int lastPCs[]; private int lastOpcode; @@ -125,14 +125,15 @@ if (lastLoadWasString && (lastPCs[0] != -1)) { byte[] bytes = getCode().getCode(); int loadIns = get1Byte(bytes, lastPCs[2]); - + int brOffset = (loadIns == ALOAD) ? 11 : 10; + if ((((loadIns >= ALOAD_0) && (loadIns <= ALOAD_3)) || (loadIns == ALOAD)) && (get1Byte(bytes, lastPCs[3]) == INVOKEVIRTUAL) && (get1Byte(bytes, lastPCs[2]) == loadIns) && (get1Byte(bytes, lastPCs[1]) == IFNULL) && (get1Byte(bytes, lastPCs[0]) == loadIns) && ((loadIns != ALOAD) || (get1Byte(bytes, lastPCs[2]+1) == get1Byte(bytes, lastPCs[0]+1))) - && ((seen == IFNE) ? get2Bytes(bytes, lastPCs[1]+1) > 10 : get2Bytes(bytes, lastPCs[1]+1) == 10)) { + && ((seen == IFNE) ? get2Bytes(bytes, lastPCs[1]+1) > brOffset : get2Bytes(bytes, lastPCs[1]+1) == brOffset)) { ConstantPool pool = getConstantPool(); int mpoolIndex = get2Bytes(bytes, lastPCs[3]+1); ConstantMethodref cmr = (ConstantMethodref)pool.getConstant(mpoolIndex); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-11-22 06:23:19
|
Revision: 971 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=971&view=rev Author: dbrosius Date: 2007-11-21 22:23:23 -0800 (Wed, 21 Nov 2007) Log Message: ----------- look for .toString calls on stringbuffer/stringbuilder just to get the length. 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-11-21 13:26:13 UTC (rev 970) +++ trunk/fb-contrib/etc/findbugs.xml 2007-11-22 06:23:23 UTC (rev 971) @@ -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" /> + 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" /> <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" @@ -388,6 +388,7 @@ <BugPattern abbrev="SPP" type="SPP_USE_CHARAT" category="PERFORMANCE" /> <BugPattern abbrev="SPP" type="SPP_USELESS_TRINARY" category="PERFORMANCE" /> <BugPattern abbrev="SPP" type="SPP_SUSPECT_STRING_TEST" category="CORRECTNESS" /> + <BugPattern abbrev="SPP" type="SPP_USE_STRINGBUILDER_LENGTH" category="PERFORMANCE" /> <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-11-21 13:26:13 UTC (rev 970) +++ trunk/fb-contrib/etc/messages.xml 2007-11-22 06:23:23 UTC (rev 971) @@ -1913,6 +1913,18 @@ </Details> </BugPattern> + <BugPattern type="SPP_USE_STRINGBUILDER_LENGTH"> + <ShortDescription>Method converts StringBuffer or Builder to String just to get it's length</ShortDescription> + <LongDescription>Method {1} converts StringBuffer or Builder to String just to get it's length</LongDescription> + <Details> + <![CDATA[ + <p>This method calls the toString method on a StringBuffer or StringBuilder only to call length() on the resulting + string. It is faster, and less memory intensive to just call the length method directly on the StringBuffer or StringBuilder + itself.</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-11-21 13:26:13 UTC (rev 970) +++ trunk/fb-contrib/samples/SPP_Sample.java 2007-11-22 06:23:23 UTC (rev 971) @@ -156,4 +156,12 @@ System.out.println("Booya"); } } + + public void sbToString(StringBuffer sb) + { + if (sb.toString().length() == 0) + System.out.println("Booya"); + else if (sb.toString().equals("")) + System.out.println("Booya"); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-11-21 13:26:13 UTC (rev 970) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-11-22 06:23:23 UTC (rev 971) @@ -26,10 +26,12 @@ import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.Constant; import org.apache.bcel.classfile.ConstantDouble; import org.apache.bcel.classfile.ConstantMethodref; import org.apache.bcel.classfile.ConstantNameAndType; import org.apache.bcel.classfile.ConstantPool; +import org.apache.bcel.classfile.ConstantString; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.LocalVariable; import org.apache.bcel.classfile.LocalVariableTable; @@ -149,12 +151,72 @@ } } - - if (seen == IFEQ) { + if (seen == IFNE) { + byte[] bytes = getCode().getCode(); + if (lastPCs[2] != -1) { + if ((getbyte(bytes, lastPCs[3]) == INVOKEVIRTUAL) + && (getbyte(bytes, lastPCs[2]) == INVOKEVIRTUAL)) { + ConstantPool pool = getConstantPool(); + int toStringIndex = getshort(bytes, lastPCs[2]+1); + ConstantMethodref toStringMR = (ConstantMethodref)pool.getConstant(toStringIndex); + String toStringCls = toStringMR.getClass(pool); + if (toStringCls.startsWith("java.lang.StringBu")) { + int nandtIndex = toStringMR.getNameAndTypeIndex(); + ConstantNameAndType cnt = (ConstantNameAndType)pool.getConstant(nandtIndex); + if ("toString".equals(cnt.getName(pool))) { + int lengthIndex = getshort(bytes, lastPCs[3]+1); + ConstantMethodref lengthMR = (ConstantMethodref)pool.getConstant(lengthIndex); + nandtIndex = lengthMR.getNameAndTypeIndex(); + cnt = (ConstantNameAndType)pool.getConstant(nandtIndex); + if ("length".equals(cnt.getName(pool))) { + bugReporter.reportBug(new BugInstance(this, "SPP_USE_STRINGBUILDER_LENGTH", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + } + } + } else if (seen == IFEQ) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); lastIfEqWasBoolean = "Z".equals(itm.getElementSignature()); } + + byte[] bytes = getCode().getCode(); + if (lastPCs[1] != -1) { + if ((getbyte(bytes, lastPCs[3]) == INVOKEVIRTUAL) + && (getbyte(bytes, lastPCs[2]) == LDC) + && (getbyte(bytes, lastPCs[1]) == INVOKEVIRTUAL)) { + ConstantPool pool = getConstantPool(); + int toStringIndex = getshort(bytes, lastPCs[1]+1); + ConstantMethodref toStringMR = (ConstantMethodref)pool.getConstant(toStringIndex); + String toStringCls = toStringMR.getClass(pool); + if (toStringCls.startsWith("java.lang.StringBu")) { + int consIndex = getbyte(bytes, lastPCs[2]+1); + Constant c = pool.getConstant(consIndex); + if (c instanceof ConstantString) { + if ("".equals(((ConstantString) c).getBytes(pool))) { + int nandtIndex = toStringMR.getNameAndTypeIndex(); + ConstantNameAndType cnt = (ConstantNameAndType)pool.getConstant(nandtIndex); + if ("toString".equals(cnt.getName(pool))) { + int lengthIndex = getshort(bytes, lastPCs[3]+1); + ConstantMethodref lengthMR = (ConstantMethodref)pool.getConstant(lengthIndex); + nandtIndex = lengthMR.getNameAndTypeIndex(); + cnt = (ConstantNameAndType)pool.getConstant(nandtIndex); + if ("equals".equals(cnt.getName(pool))) { + bugReporter.reportBug(new BugInstance(this, "SPP_USE_STRINGBUILDER_LENGTH", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + } + } + } + } } else if ((seen == IRETURN) && lastIfEqWasBoolean) { byte[] bytes = getCode().getCode(); if ((lastPCs[0] != -1) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-11-23 00:42:00
|
Revision: 973 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=973&view=rev Author: dbrosius Date: 2007-11-22 16:42:03 -0800 (Thu, 22 Nov 2007) Log Message: ----------- get ready for 3.4.2 Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2007-11-23 00:31:52 UTC (rev 972) +++ trunk/fb-contrib/build.xml 2007-11-23 00:42:03 UTC (rev 973) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.5.0"/> + <property name="fb-contrib.version" value="3.4.2"/> <target name="clean" description="removes all generated collateral"> <delete dir="${classes.dir}"/> @@ -162,7 +162,7 @@ failOnError="true"> <class location="${basedir}/fb-contrib-${fb-contrib.version}.jar"/> </findbugs> - <delete dir="${basedir}/plugin"/> + <!--<delete dir="${basedir}/plugin"/>--> </target> <target name="build" depends="clean, -init, validate_xml, compile, compile_samples, jar" description="builds the plugin jar"> Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-11-23 00:31:52 UTC (rev 972) +++ trunk/fb-contrib/etc/findbugs.xml 2007-11-23 00:42:03 UTC (rev 973) @@ -302,7 +302,8 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.ConfusingFunctionSemantics" speed="fast" - reports="CFS_CONFUSING_FUNCTION_SEMANTICS" /> + reports="CFS_CONFUSING_FUNCTION_SEMANTICS" + hidden="true" /> <!-- BugPattern --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-11-23 00:52:27
|
Revision: 975 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=975&view=rev Author: dbrosius Date: 2007-11-22 16:52:32 -0800 (Thu, 22 Nov 2007) Log Message: ----------- go back to 3.5.0 dev Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2007-11-23 00:45:11 UTC (rev 974) +++ trunk/fb-contrib/build.xml 2007-11-23 00:52:32 UTC (rev 975) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.4.2"/> + <property name="fb-contrib.version" value="3.5.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-11-23 00:45:11 UTC (rev 974) +++ trunk/fb-contrib/etc/findbugs.xml 2007-11-23 00:52:32 UTC (rev 975) @@ -302,8 +302,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.ConfusingFunctionSemantics" speed="fast" - reports="CFS_CONFUSING_FUNCTION_SEMANTICS" - hidden="true" /> + reports="CFS_CONFUSING_FUNCTION_SEMANTICS" /> <!-- BugPattern --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-11-23 03:50:45
|
Revision: 976 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=976&view=rev Author: dbrosius Date: 2007-11-22 19:50:50 -0800 (Thu, 22 Nov 2007) Log Message: ----------- add checks for Boolean constant boxing Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/samples/NAB_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-11-23 00:52:32 UTC (rev 975) +++ trunk/fb-contrib/etc/findbugs.xml 2007-11-23 03:50:50 UTC (rev 976) @@ -115,7 +115,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessAutoboxing" speed="fast" - reports="NAB_NEEDLESS_AUTOBOXING_CTOR,NAB_NEEDLESS_BOXING_STRING_CTOR,NAB_NEEDLESS_AUTOBOXING_VALUEOF,NAB_NEEDLESS_BOXING_PARSE,NAB_NEEDLESS_BOXING_VALUEOF,NAB_NEEDLESS_BOX_TO_UNBOX,NAB_NEEDLESS_BOX_TO_CAST" /> + reports="NAB_NEEDLESS_AUTOBOXING_CTOR,NAB_NEEDLESS_BOXING_STRING_CTOR,NAB_NEEDLESS_AUTOBOXING_VALUEOF,NAB_NEEDLESS_BOXING_PARSE,NAB_NEEDLESS_BOXING_VALUEOF,NAB_NEEDLESS_BOX_TO_UNBOX,NAB_NEEDLESS_BOX_TO_CAST,NAB_NEEDLESS_BOOLEAN_CONSTANT_CONVERSION" /> <Detector class="com.mebigfatguy.fbcontrib.detect.UnnecessaryStoreBeforeReturn" speed="fast" @@ -335,6 +335,7 @@ <BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOXING_VALUEOF" category="PERFORMANCE" /> <BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOX_TO_UNBOX" category="PERFORMANCE" /> <BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOX_TO_CAST" category="PERFORMANCE" /> + <BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOOLEAN_CONSTANT_CONVERSION" category="PERFORMANCE" /> <BugPattern abbrev="USBR" type="USBR_UNNECESSARY_STORE_BEFORE_RETURN" category="STYLE" /> <BugPattern abbrev="COM" type="COM_COPIED_OVERRIDDEN_METHOD" category="STYLE" /> <BugPattern abbrev="ABC" type="ABC_ARRAY_BASED_COLLECTIONS" category="CORRECTNESS" /> Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-11-23 00:52:32 UTC (rev 975) +++ trunk/fb-contrib/etc/messages.xml 2007-11-23 03:50:50 UTC (rev 976) @@ -1208,6 +1208,26 @@ ]]> </Details> </BugPattern> + + <BugPattern type="NAB_NEEDLESS_BOOLEAN_CONSTANT_CONVERSION"> + <ShortDescription>method needlessly boxes a boolean constant</ShortDescription> + <LongDescription>method {1} needlessly boxes a boolean constant</LongDescription> + <Details> + <![CDATA[ + <p>This method assigns a Boxed boolean constant to a primitive boolean variable, or assigns a primitive boolean + constant to a Boxed boolean variable. Use the correct constant for the variable desired. Use</p> + <pre> + boolean b = true; + boolean b = false; + + or + + Boolean b = Boolean.TRUE; + Boolean b = Boolean.FALSE; + </pre> + ]]> + </Details> + </BugPattern> <BugPattern type="USBR_UNNECESSARY_STORE_BEFORE_RETURN"> <ShortDescription>method stores return result in local before immediately returning it</ShortDescription> Modified: trunk/fb-contrib/samples/NAB_Sample.java =================================================================== --- trunk/fb-contrib/samples/NAB_Sample.java 2007-11-23 00:52:32 UTC (rev 975) +++ trunk/fb-contrib/samples/NAB_Sample.java 2007-11-23 03:50:50 UTC (rev 976) @@ -122,4 +122,12 @@ d = new Double(6.0).floatValue(); d = Double.valueOf(6.0).floatValue(); } + + public void testBooleanConsts() + { + boolean b = Boolean.FALSE; + b = Boolean.TRUE; + Boolean bb = false; + bb = true; + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-11-23 00:52:32 UTC (rev 975) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-11-23 03:50:50 UTC (rev 976) @@ -40,6 +40,8 @@ private static final int SEEN_PARSE = 3; private static final int SEEN_CTOR = 4; private static final int SEEN_VALUEOFPRIMITIVE = 5; + private static final int SEEN_ICONST = 6; + private static final int SEEN_GETSTATIC = 7; private static final Map<String, String[]> boxClasses = new HashMap<String, String[]>(); static { @@ -125,6 +127,15 @@ state = SEEN_CTOR; } } + } else if ((seen == ICONST_0) || (seen == ICONST_1)) { + state = SEEN_ICONST; + } else if (seen == GETSTATIC) { + String clsName = getClassConstantOperand(); + String fldName = getNameConstantOperand(); + if ("java/lang/Boolean".equals(clsName)) { + if ("TRUE".equals(fldName) || "FALSE".equals(fldName)) + state = SEEN_GETSTATIC; + } } break; @@ -213,6 +224,34 @@ } state = SEEN_NOTHING; break; + + case SEEN_ICONST: + if (seen == INVOKESTATIC) { + if (("java/lang/Boolean".equals(getClassConstantOperand()) + && ("valueOf".equals(getNameConstantOperand()) + && ("(Z)Ljava/lang/Boolean;".equals(getSigConstantOperand()))))) { + bugReporter.reportBug(new BugInstance(this, "NAB_NEEDLESS_BOOLEAN_CONSTANT_CONVERSION", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + state = SEEN_NOTHING; + break; + + case SEEN_GETSTATIC: + if (seen == INVOKEVIRTUAL) { + if (("java/lang/Boolean".equals(getClassConstantOperand()) + && ("booleanValue".equals(getNameConstantOperand()) + && ("()Z".equals(getSigConstantOperand()))))) { + bugReporter.reportBug(new BugInstance(this, "NAB_NEEDLESS_BOOLEAN_CONSTANT_CONVERSION", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + state = SEEN_NOTHING; + break; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-11-23 07:58:58
|
Revision: 977 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=977&view=rev Author: dbrosius Date: 2007-11-22 23:59:00 -0800 (Thu, 22 Nov 2007) Log Message: ----------- remove fps due to compiler generated boolean trinaries Modified Paths: -------------- trunk/fb-contrib/samples/NAB_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java Modified: trunk/fb-contrib/samples/NAB_Sample.java =================================================================== --- trunk/fb-contrib/samples/NAB_Sample.java 2007-11-23 03:50:50 UTC (rev 976) +++ trunk/fb-contrib/samples/NAB_Sample.java 2007-11-23 07:59:00 UTC (rev 977) @@ -123,11 +123,13 @@ d = Double.valueOf(6.0).floatValue(); } - public void testBooleanConsts() + public Boolean testBooleanConsts(String s) { boolean b = Boolean.FALSE; b = Boolean.TRUE; Boolean bb = false; bb = true; + + return Boolean.valueOf(s.equals("true") && bb.booleanValue()); } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-11-23 03:50:50 UTC (rev 976) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-11-23 07:59:00 UTC (rev 977) @@ -40,8 +40,9 @@ private static final int SEEN_PARSE = 3; private static final int SEEN_CTOR = 4; private static final int SEEN_VALUEOFPRIMITIVE = 5; - private static final int SEEN_ICONST = 6; - private static final int SEEN_GETSTATIC = 7; + private static final int SEEN_GOTO = 6; + private static final int SEEN_ICONST = 7; + private static final int SEEN_GETSTATIC = 8; private static final Map<String, String[]> boxClasses = new HashMap<String, String[]>(); static { @@ -88,6 +89,7 @@ switch (state) { case SEEN_NOTHING: + case SEEN_GOTO: if (seen == INVOKEVIRTUAL) { boxClass = getClassConstantOperand(); String[] boxSigs = boxClasses.get(boxClass); @@ -128,7 +130,8 @@ } } } else if ((seen == ICONST_0) || (seen == ICONST_1)) { - state = SEEN_ICONST; + if (state == SEEN_NOTHING) + state = SEEN_ICONST; } else if (seen == GETSTATIC) { String clsName = getClassConstantOperand(); String fldName = getNameConstantOperand(); @@ -136,6 +139,8 @@ if ("TRUE".equals(fldName) || "FALSE".equals(fldName)) state = SEEN_GETSTATIC; } + } else if (seen == GOTO) { + state = SEEN_GOTO; } break; @@ -237,6 +242,7 @@ } } state = SEEN_NOTHING; + sawOpcode(seen); break; case SEEN_GETSTATIC: @@ -251,8 +257,8 @@ } } state = SEEN_NOTHING; + sawOpcode(seen); break; - } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-01-10 05:30:18
|
Revision: 982 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=982&view=rev Author: dbrosius Date: 2008-01-09 21:30:23 -0800 (Wed, 09 Jan 2008) Log Message: ----------- Initial checkin JAO detector Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/samples/samples.fb Added Paths: ----------- trunk/fb-contrib/samples/JAO_Sample.java trunk/fb-contrib/samples/lib/junit.jar trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JUnitAssertionOddities.java Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2007-11-24 15:59:04 UTC (rev 981) +++ trunk/fb-contrib/build.xml 2008-01-10 05:30:23 UTC (rev 982) @@ -45,6 +45,7 @@ </path> <path id="fb-contrib.samples.classpath"> <pathelement location="${sampleslib.dir}/jsp-api.jar"/> + <pathelement location="${sampleslib.dir}/junit.jar"/> </path> <mkdir dir="${classes.dir}/com"/> <mkdir dir="${classes.dir}/com/mebigfatguy"/> Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-11-24 15:59:04 UTC (rev 981) +++ trunk/fb-contrib/etc/findbugs.xml 2008-01-10 05:30:23 UTC (rev 982) @@ -304,6 +304,10 @@ speed="fast" reports="CFS_CONFUSING_FUNCTION_SEMANTICS" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.JUnitAssertionOddities" + speed="fast" + reports="JAO_JUNIT_ASSERTION_ODDITIES_ACTUAL_CONSTANT,JAO_JUNIT_ASSERTION_ODDITIES_INEXACT_DOUBLE,JAO_JUNIT_ASSERTION_ODDITIES_BOOLEAN_ASSERT" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -404,4 +408,7 @@ <BugPattern abbrev="EXS" type="EXS_EXCEPTION_SOFTENING_HAS_CHECKED" category="STYLE" /> <BugPattern abbrev="EXS" type="EXS_EXCEPTION_SOFTENING_NO_CHECKED" category="STYLE" /> <BugPattern abbrev="CFS" type="CFS_CONFUSING_FUNCTION_SEMANTICS" category="STYLE" experimental="true" /> + <BugPattern abbrev="JAO" type="JAO_JUNIT_ASSERTION_ODDITIES_ACTUAL_CONSTANT" category="STYLE" experimental="true" /> + <BugPattern abbrev="JAO" type="JAO_JUNIT_ASSERTION_ODDITIES_INEXACT_DOUBLE" category="STYLE" experimental="true" /> + <BugPattern abbrev="JAO" type="JAO_JUNIT_ASSERTION_ODDITIES_BOOLEAN_ASSERT" category="STYLE" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-11-24 15:59:04 UTC (rev 981) +++ trunk/fb-contrib/etc/messages.xml 2008-01-10 05:30:23 UTC (rev 982) @@ -831,6 +831,23 @@ </Details> </Detector> + <Detector class="com.mebigfatguy.fbcontrib.detect.JUnitAssertionOddities"> + <Details> + <![CDATA[ + <p>looks for junit test case methods that use assertions with odd parameters. + Including in this is: + <ul> + <li>Passing a constant as the second (actual) parameter</li> + <li>not using the three parameter version of asserts for doubles</li> + <li>Passing true or false as the first parameter instead of using assertTrue, or assertFalse</li> + </ul> + </p> + <p>It is a fast detector</p> + ]]> + </Details> + </Detector> + + <!-- BugPattern --> <BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING"> @@ -2135,6 +2152,40 @@ </Details> </BugPattern> + <BugPattern type="JAO_JUNIT_ASSERTION_ODDITIES_ACTUAL_CONSTANT"> + <ShortDescription>method passes constant to second (actual) assertion parameter</ShortDescription> + <LongDescription>method {1} passes constant to second (actual) assertion parameter</LongDescription> + <Details> + <![CDATA[ + <p>This method calls assert passing a constant value as the second of the two values. The assert + method assumes that the expected value is the first parameter, and so it appears that the order + of values has been swapped here.</p> + ]]> + </Details> + </BugPattern> + + <BugPattern type="JAO_JUNIT_ASSERTION_ODDITIES_INEXACT_DOUBLE"> + <ShortDescription>method asserts that two doubles are exactly equal</ShortDescription> + <LongDescription>method {1} asserts that two doubles are exactly equal</LongDescription> + <Details> + <![CDATA[ + <p>This method calls assert with two doubles or Doubles. Due to the inprecision of doubles, you + should be using the assert method that takes a range parameter that gives a range of error.</p> + ]]> + </Details> + </BugPattern> + + <BugPattern type="JAO_JUNIT_ASSERTION_ODDITIES_BOOLEAN_ASSERT"> + <ShortDescription>method asserts that a value is true or false</ShortDescription> + <LongDescription>method {1} asserts that a value is true or false</LongDescription> + <Details> + <![CDATA[ + <p>This method asserts that a value is equal to true or false. It is simpler to just + use assertTrue, or assertFalse, instead.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -2205,4 +2256,5 @@ <BugCode abbrev="MOM">Misleading Overload Model</BugCode> <BugCode abbrev="EXS">Exception Softening</BugCode> <BugCode abbrev="CFS">Confusing Function Semantics</BugCode> + <BugCode abbrev="JAO">JUnit Assertion Oddities</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/JAO_Sample.java =================================================================== --- trunk/fb-contrib/samples/JAO_Sample.java (rev 0) +++ trunk/fb-contrib/samples/JAO_Sample.java 2008-01-10 05:30:23 UTC (rev 982) @@ -0,0 +1,27 @@ +import junit.framework.Assert; +import junit.framework.TestCase; + + +public class JAO_Sample extends TestCase +{ + + public void testExactDoubles(double d1, double d2) + { + Assert.assertEquals(d1, d2); + } + + public void testTrue(boolean b) + { + Assert.assertEquals(true, b); + } + + public void testFalse(boolean b) + { + Assert.assertEquals("Wow this is bad", false, b); + } + + public void testWrongOrder(int i) + { + Assert.assertEquals(i, 10); + } +} Property changes on: trunk/fb-contrib/samples/JAO_Sample.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/fb-contrib/samples/lib/junit.jar =================================================================== (Binary files differ) Property changes on: trunk/fb-contrib/samples/lib/junit.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/fb-contrib/samples/samples.fb =================================================================== --- trunk/fb-contrib/samples/samples.fb 2007-11-24 15:59:04 UTC (rev 981) +++ trunk/fb-contrib/samples/samples.fb 2008-01-10 05:30:23 UTC (rev 982) @@ -4,5 +4,6 @@ . [Aux classpath entries] .\lib\jsp-api.jar +.\lib\junit.jar [Options] relative_paths=true Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JUnitAssertionOddities.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JUnitAssertionOddities.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JUnitAssertionOddities.java 2008-01-10 05:30:23 UTC (rev 982) @@ -0,0 +1,181 @@ +/* + * fb-contrib - Auxiliary detectors for Java programs + * Copyright (C) 2005-2007 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.Repository; +import org.apache.bcel.classfile.Attribute; +import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.Constant; +import org.apache.bcel.classfile.ConstantPool; +import org.apache.bcel.classfile.ConstantUtf8; +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; +import org.apache.bcel.classfile.Unknown; +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 odd uses of the Assert class of the JUnit framework */ +public class JUnitAssertionOddities extends BytecodeScanningDetector +{ + private static final String RUNTIME_VISIBLE_ANNOTATIONS = "RuntimeVisibleAnnotations"; + private static final String TEST_ANNOTATION_SIGNATURE = "Lorg/junit/Test;"; + private static final String OLD_ASSERT_CLASS = "junit/framework/Assert"; + private static final String NEW_ASSERT_CLASS = "org/junit/Assert"; + private static JavaClass testCaseClass; + private static JavaClass testAnnotationClass; + static { + try { + testCaseClass = Repository.lookupClass("junit.framework.TestCase"); + } catch (ClassNotFoundException cnfe) { + testCaseClass = null; + } + try { + testAnnotationClass = Repository.lookupClass("org.junit.Test"); + } catch (ClassNotFoundException cnfe) { + testAnnotationClass = null; + } + } + private BugReporter bugReporter; + private OpcodeStack stack; + private boolean isTestCaseDerived; + private boolean isAnnotationCapable; + + /** + * constructs a JOA detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ + public JUnitAssertionOddities(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** + * override the visitor to see if this class could be a test class + * + * @param classContext the context object of the currently parsed class + */ + @Override + public void visitClassContext(ClassContext classContext) { + try { + JavaClass cls = classContext.getJavaClass(); + isTestCaseDerived = ((testCaseClass != null) && cls.instanceOf(testCaseClass)); + isAnnotationCapable = (cls.getMajor() >= 5) && (testAnnotationClass != null); + if (isTestCaseDerived || isAnnotationCapable) { + stack = new OpcodeStack(); + super.visitClassContext(classContext); + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } finally { + stack = null; + } + } + + @Override + public void visitCode(Code obj) { + Method m = getMethod(); + boolean isTestMethod = isTestCaseDerived && m.getName().startsWith("test"); + + if (!isTestMethod && isAnnotationCapable) { + Attribute[] atts = m.getAttributes(); + for (Attribute att : atts) { + ConstantPool cp = att.getConstantPool(); + Constant c = cp.getConstant(att.getNameIndex()); + if (c instanceof ConstantUtf8) { + String name = ((ConstantUtf8) c).getBytes(); + if (RUNTIME_VISIBLE_ANNOTATIONS.equals(name)) { + if (att instanceof Unknown) { + Unknown unAtt = (Unknown)att; + byte[] bytes = unAtt.getBytes(); + int constantPoolIndex = bytes[3]; + c = cp.getConstant(constantPoolIndex); + if (c instanceof ConstantUtf8) { + name = ((ConstantUtf8) c).getBytes(); + if (TEST_ANNOTATION_SIGNATURE.equals(name)) { + isTestMethod = true; + break; + } + } + } + } + } + } + } + + if (isTestMethod) { + stack.resetForMethodEntry(this); + super.visitCode(obj); + } + } + + @Override + public void sawOpcode(int seen) { + try { + stack.mergeJumps(this); + + if (seen == INVOKESTATIC) { + String clsName = getClassConstantOperand(); + if (OLD_ASSERT_CLASS.equals(clsName) || NEW_ASSERT_CLASS.equals(clsName)) { + String methodName = getNameConstantOperand(); + if ("assertEquals".equals(methodName)) { + String signature = getSigConstantOperand(); + Type[] argTypes = Type.getArgumentTypes(signature); + if (argTypes[0].equals(Type.STRING) && argTypes[1].equals(Type.STRING)) + return; + + if (stack.getStackDepth() >= 2) { + OpcodeStack.Item item1 = stack.getStackItem(1); + Object cons1 = item1.getConstant(); + if ((cons1 != null) && (argTypes[argTypes.length-1].equals(Type.BOOLEAN)) && (argTypes[argTypes.length-2].equals(Type.BOOLEAN))) { + bugReporter.reportBug(new BugInstance(this, "JAO_JUNIT_ASSERTION_ODDITIES_BOOLEAN_ASSERT", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + return; + } + OpcodeStack.Item item0 = stack.getStackItem(0); + if (item0.getConstant() != null) { + bugReporter.reportBug(new BugInstance(this, "JAO_JUNIT_ASSERTION_ODDITIES_ACTUAL_CONSTANT", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + return; + } + if (argTypes[0].equals(Type.OBJECT) && argTypes[1].equals(Type.OBJECT)) { + if ("Ljava/lang/Double;".equals(item0.getSignature()) && "Ljava/lang/Double;".equals(item1.getSignature())) { + bugReporter.reportBug(new BugInstance(this, "JAO_JUNIT_ASSERTION_ODDITIES_INEXACT_DOUBLE", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + return; + } + } + } + } + } + } + } finally { + stack.sawOpcode(this, seen); + } + } +} Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JUnitAssertionOddities.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-03-09 03:25:38
|
Revision: 989 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=989&view=rev Author: dbrosius Date: 2008-03-08 19:25:44 -0800 (Sat, 08 Mar 2008) Log Message: ----------- initial checkin of new SCA detector Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/SCA_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousCloneAlgorithm.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2008-01-20 13:29:48 UTC (rev 988) +++ trunk/fb-contrib/etc/findbugs.xml 2008-03-09 03:25:44 UTC (rev 989) @@ -308,6 +308,10 @@ speed="fast" reports="JAO_JUNIT_ASSERTION_ODDITIES_ACTUAL_CONSTANT,JAO_JUNIT_ASSERTION_ODDITIES_INEXACT_DOUBLE,JAO_JUNIT_ASSERTION_ODDITIES_BOOLEAN_ASSERT" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousCloneAlgorithm" + speed="fast" + reports="SCA_SUSPICIOUS_CLONE_ALGORITHM" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -411,4 +415,5 @@ <BugPattern abbrev="JAO" type="JAO_JUNIT_ASSERTION_ODDITIES_ACTUAL_CONSTANT" category="STYLE" experimental="true" /> <BugPattern abbrev="JAO" type="JAO_JUNIT_ASSERTION_ODDITIES_INEXACT_DOUBLE" category="STYLE" experimental="true" /> <BugPattern abbrev="JAO" type="JAO_JUNIT_ASSERTION_ODDITIES_BOOLEAN_ASSERT" category="STYLE" experimental="true" /> + <BugPattern abbrev="SCA" type="SCA_SUSPICIOUS_CLONE_ALGORITHM" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2008-01-20 13:29:48 UTC (rev 988) +++ trunk/fb-contrib/etc/messages.xml 2008-03-09 03:25:44 UTC (rev 989) @@ -846,6 +846,15 @@ ]]> </Details> </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousCloneAlgorithm"> + <Details> + <![CDATA[ + <p>looks for implementation of clone where an assignment is made to a field of the + source object. It is likely that that store should have occurred on the cloned object, as + the clone operation is almost always considered read only.</p>]]> + </Details> + </Detector> <!-- BugPattern --> @@ -2186,6 +2195,17 @@ </Details> </BugPattern> + <BugPattern type="SCA_SUSPICIOUS_CLONE_ALGORITHM"> + <ShortDescription>clone method stores a new value to member field of source object</ShortDescription> + <LongDescription>clone method {1} stores a new value to member field of source object</LongDescription> + <Details> + <![CDATA[ + <p>The clone method stores a value to a member field of the source object. Normally, all + changes are made to the cloned object, and given that cloning is almost always considered + a read-only operation, this seems incorrect.</p>]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -2257,4 +2277,5 @@ <BugCode abbrev="EXS">Exception Softening</BugCode> <BugCode abbrev="CFS">Confusing Function Semantics</BugCode> <BugCode abbrev="JAO">JUnit Assertion Oddities</BugCode> + <BugCode abbrev="SCA">Suspicious Clone Algorithm</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/SCA_Sample.java =================================================================== --- trunk/fb-contrib/samples/SCA_Sample.java (rev 0) +++ trunk/fb-contrib/samples/SCA_Sample.java 2008-03-09 03:25:44 UTC (rev 989) @@ -0,0 +1,16 @@ +import java.util.ArrayList; +import java.util.List; + + +public class SCA_Sample implements Cloneable +{ + private List<String> names = new ArrayList<String>(); + + public Object clone() throws CloneNotSupportedException { + SCA_Sample s = (SCA_Sample)super.clone(); + names = new ArrayList<String>(); + s.names.addAll(names); + names.add("New"); + return s; + } +} Property changes on: trunk/fb-contrib/samples/SCA_Sample.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousCloneAlgorithm.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousCloneAlgorithm.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousCloneAlgorithm.java 2008-03-09 03:25:44 UTC (rev 989) @@ -0,0 +1,179 @@ +/* + * fb-contrib - Auxiliary detectors for Java programs + * Copyright (C) 2005-2008 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 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.classfile.Method; +import org.apache.bcel.generic.Type; + +import com.mebigfatguy.fbcontrib.utils.Integer14; + +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 implementation of clone() where a store is made to a member + * of the source object. + */ +public class SuspiciousCloneAlgorithm extends BytecodeScanningDetector { + + private static JavaClass cloneableClass; + private static Map<String, Integer> changingMethods; + static { + try { + cloneableClass = Repository.lookupClass("java/lang/Cloneable"); + changingMethods = new HashMap<String, Integer>(); + changingMethods.put("add", Integer14.valueOf(NORMAL_PRIORITY)); + changingMethods.put("addAll", Integer14.valueOf(NORMAL_PRIORITY)); + changingMethods.put("put", Integer14.valueOf(NORMAL_PRIORITY)); + changingMethods.put("putAll", Integer14.valueOf(NORMAL_PRIORITY)); + changingMethods.put("insert", Integer14.valueOf(LOW_PRIORITY)); + changingMethods.put("set", Integer14.valueOf(LOW_PRIORITY)); + + } catch (ClassNotFoundException cnfe) { + cloneableClass = null; + } + } + + private BugReporter bugReporter; + private OpcodeStack stack; + + /** + * constructs a SCA detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ + public SuspiciousCloneAlgorithm(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** + * override the visitor to look for classes that implement Cloneable + * + * @param classContext the context object of the class to be checked + */ + @Override + public void visitClassContext(ClassContext classContext) { + if (cloneableClass == null) + return; + + try { + JavaClass cls = classContext.getJavaClass(); + if (cls.implementationOf(cloneableClass)) { + stack = new OpcodeStack(); + super.visitClassContext(classContext); + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } finally { + stack = null; + } + } + + /** + * override the visitor to only continue for the clone method + * + * @param obj the context object of the currently parsed method + */ + @Override + public void visitCode(Code obj) { + Method m = getMethod(); + if (!m.isStatic() && "clone".equals(m.getName()) && "()Ljava/lang/Object;".equals(m.getSignature())) + super.visitCode(obj); + } + + /** + * override the visitor to look for stores to member fields of the source object on a clone + * + * @param seen the opcode of the currently parsed instruction + */ + @Override + public void sawOpcode(int seen) { + boolean srcField = false; + try { + stack.mergeJumps(this); + switch (seen) { + case ALOAD_0: + srcField = true; + break; + + case DUP: + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + if (item.getUserValue() != null) + srcField = true; + } + break; + + case GETFIELD: + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + if (item.getRegisterNumber() == 0) { + srcField = true; + } + } + break; + + case PUTFIELD: + if (stack.getStackDepth() >= 2) { + OpcodeStack.Item item = stack.getStackItem(1); + if ((item.getRegisterNumber() == 0) || (item.getUserValue() != null)) { + bugReporter.reportBug(new BugInstance(this, "SCA_SUSPICIOUS_CLONE_ALGORITHM", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + + break; + + case INVOKEINTERFACE: + case INVOKEVIRTUAL: + String sig = getSigConstantOperand(); + int numArgs = Type.getArgumentTypes(sig).length; + if (stack.getStackDepth() > numArgs) { + OpcodeStack.Item item = stack.getStackItem(numArgs); + if ((item.getRegisterNumber() == 0) || (item.getUserValue() != null)) { + String name = getNameConstantOperand(); + Integer priority = changingMethods.get(name); + if (priority != null) + bugReporter.reportBug(new BugInstance(this, "SCA_SUSPICIOUS_CLONE_ALGORITHM", priority.intValue()) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + break; + } + } finally { + stack.sawOpcode(this, seen); + if (srcField && stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + item.setUserValue(Boolean.TRUE); + } + } + } +} Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousCloneAlgorithm.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-03-09 03:38:52
|
Revision: 990 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=990&view=rev Author: dbrosius Date: 2008-03-08 19:35:10 -0800 (Sat, 08 Mar 2008) Log Message: ----------- update documentation to note that static methods also may return MRC issues, but at a LOW_PRIORITY Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MethodReturnsConstant.java Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2008-03-09 03:25:44 UTC (rev 989) +++ trunk/fb-contrib/etc/messages.xml 2008-03-09 03:35:10 UTC (rev 990) @@ -770,7 +770,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.MethodReturnsConstant"> <Details> <![CDATA[ - <p>looks for private methods that only return one constant value. Since there is no + <p>looks for private or static methods that only return one constant value. Since there is no chance for derived classes overriding this behavior, the return of a constant value seems dubious.</p> <p>It is a fast detector</p> @@ -2078,7 +2078,7 @@ <LongDescription>private method {1} only returns one constant value</LongDescription> <Details> <![CDATA[ - <p>This private method only returns one constant value. As this method is private, + <p>This private or static method only returns one constant value. As this method is private or static, it's behavior can't be overridden, and thus the return of a constant value seems dubious. Either the method should be changed to return no value, or perhaps another return value was expected to be returned in another code path in this method.</p> Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MethodReturnsConstant.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MethodReturnsConstant.java 2008-03-09 03:25:44 UTC (rev 989) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MethodReturnsConstant.java 2008-03-09 03:35:10 UTC (rev 990) @@ -75,7 +75,7 @@ returnPC = -1; super.visitCode(obj); if (methodSuspect && (returnConstant != null)) { - BugInstance bi = new BugInstance(this, "MRC_METHOD_RETURNS_CONSTANT", NORMAL_PRIORITY) + BugInstance bi = new BugInstance(this, "MRC_METHOD_RETURNS_CONSTANT", ((aFlags & Constants.ACC_PRIVATE) != 0) ? NORMAL_PRIORITY : LOW_PRIORITY) .addClass(this) .addMethod(this); if (returnPC >= 0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-03-09 04:03:10
|
Revision: 993 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=993&view=rev Author: dbrosius Date: 2008-03-08 20:03:15 -0800 (Sat, 08 Mar 2008) Log Message: ----------- allow for arguments that have paths specified with / Modified Paths: -------------- trunk/fb-contrib/samples/ITC_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java Modified: trunk/fb-contrib/samples/ITC_Sample.java =================================================================== --- trunk/fb-contrib/samples/ITC_Sample.java 2008-03-09 03:46:50 UTC (rev 992) +++ trunk/fb-contrib/samples/ITC_Sample.java 2008-03-09 04:03:15 UTC (rev 993) @@ -5,8 +5,19 @@ public class ITC_Sample { - public String test(List<String> l) + class A { + + } + + class B extends A + {} + + class C extends A + {} + + public String testOthers(List<String> l) + { if (l instanceof ArrayList) return (String)((ArrayList)l).remove(0); else if (l instanceof LinkedList) @@ -16,4 +27,14 @@ else return null; } + + public String testMine(A a) + { + if (a instanceof B) + return "Yes"; + else if (a instanceof C) + return "No"; + else + return "Unknown"; + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2008-03-09 03:46:50 UTC (rev 992) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2008-03-09 04:03:15 UTC (rev 993) @@ -47,10 +47,13 @@ * * @return if they are similar */ - public static boolean similarPackages(final String packName1, final String packName2, int depth) { + public static boolean similarPackages(String packName1, String packName2, int depth) { if (depth == 0) return true; + packName1 = packName1.replace('/', '.'); + packName2 = packName2.replace('/', '.'); + int dot1 = packName1.indexOf('.'); int dot2 = packName2.indexOf('.'); if (dot1 < 0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-03-15 06:17:16
|
Revision: 1005 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1005&view=rev Author: dbrosius Date: 2008-03-14 23:17:22 -0700 (Fri, 14 Mar 2008) Log Message: ----------- fix for [ 1914317 ] FalsePositive UAA_USE_ADD_ALL, postpose the reporting of UAA until you finish the loop that it occurs in, this way you can check for duplicate adds, conditional adds in ADDITION to the candidate. Modified Paths: -------------- trunk/fb-contrib/samples/UAA_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java Modified: trunk/fb-contrib/samples/UAA_Sample.java =================================================================== --- trunk/fb-contrib/samples/UAA_Sample.java 2008-03-15 04:59:43 UTC (rev 1004) +++ trunk/fb-contrib/samples/UAA_Sample.java 2008-03-15 06:17:22 UTC (rev 1005) @@ -80,7 +80,7 @@ } } - public void testAddWithCheck(List<String> src, List<String> dst) + public void testFPAddWithCheck(List<String> src, List<String> dst) { for (String s : src) { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2008-03-15 04:59:43 UTC (rev 1004) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2008-03-15 06:17:22 UTC (rev 1005) @@ -19,6 +19,7 @@ package com.mebigfatguy.fbcontrib.detect; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import org.apache.bcel.Repository; @@ -124,6 +125,22 @@ boolean sawLoad = false; try { + int pc = getPC(); + Iterator<LoopInfo> it = loops.values().iterator(); + while (it.hasNext()) { + LoopInfo loop = it.next(); + if ((loop.getEndPC()-3) <= pc) { + int loopPC = loop.getAddPC(); + if (loopPC > 0) { + bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this, loopPC)); + } + it.remove(); + } + } + if (seen == INVOKEINTERFACE) { String methodName = getNameConstantOperand(); String signature = getSigConstantOperand(); @@ -167,12 +184,13 @@ uValue = (Comparable<?>)valueItem.getUserValue(); if (uValue != null) { LoopInfo loop = loops.get(uValue); - if ((loop != null) && loop.isInLoop(getPC(), false)) { - if (this.getCodeByte(getNextPC()) == POP) { - bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + if (loop != null) { + if (loop.inConditionalRange(pc)) + loop.foundAdd(-1); + else if (loop.isInLoop(pc, false)) { + if (this.getCodeByte(getNextPC()) == POP) { + loop.foundAdd(pc); + } } } } @@ -183,11 +201,13 @@ uValue = (Comparable<?>)valueItem.getUserValue(); if (uValue != null) { LoopInfo loop = loops.get(uValue); - if ((loop != null) && loop.isInLoop(getPC(), false)) { - bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + if (loop != null) { + if (loop.inConditionalRange(pc)) + loop.foundAdd(-1); + else if (loop.isInLoop(pc, false)) + if (this.getCodeByte(getNextPC()) == POP) { + loop.foundAdd(pc); + } } } } @@ -214,11 +234,11 @@ brOffset <<= 8; brOffset |= (0x0FF & code[gotoPos+2]); gotoPos += brOffset; - if (gotoPos < getPC()) { + if (gotoPos < pc) { OpcodeStack.Item itm = stack.getStackItem(0); uValue = (Comparable<?>)itm.getUserValue(); if (uValue != null) { - loops.put(uValue, new LoopInfo(getPC(), getBranchTarget())); + loops.put(uValue, new LoopInfo(pc, getBranchTarget())); } loopFound = true; } @@ -226,9 +246,9 @@ if (!loopFound) { - LoopInfo loop = findLoop(getPC(), true); + LoopInfo loop = findLoop(pc, true); if (loop != null) { - loop.addConditionalRange(getPC(), getBranchTarget()); + loop.addConditionalRange(pc, getBranchTarget()); } } } @@ -249,9 +269,9 @@ } } } else if (((seen > IFEQ) && (seen <= GOTO)) || (seen == IFNULL) || (seen == IFNONNULL)) { - LoopInfo loop = findLoop(getPC(), true); + LoopInfo loop = findLoop(pc, true); if (loop != null) { - loop.addConditionalRange(getPC(), getBranchOffset() > 0 ? getBranchTarget() : loop.end); + loop.addConditionalRange(pc, getBranchOffset() > 0 ? getBranchTarget() : loop.end); } } else if (seen == CHECKCAST) { if (stack.getStackDepth() > 0) { @@ -352,12 +372,14 @@ { private int start; private int end; + private int addPC; private Map<Integer, Integer> conditionalRanges = new HashMap<Integer, Integer>(); public LoopInfo(int loopStart, int loopEnd) { start = loopStart; end = loopEnd; + addPC = 0; } public void addConditionalRange(int condStart, int condEnd) @@ -365,6 +387,16 @@ conditionalRanges.put(Integer14.valueOf(condStart), Integer14.valueOf(condEnd)); } + public boolean inConditionalRange(int pc) { + for (Map.Entry<Integer, Integer> entry : conditionalRanges.entrySet()) + { + if ((pc >= entry.getKey().intValue()) && pc <= entry.getValue().intValue()) + return true; + } + + return false; + } + public boolean isInLoop(int pc, boolean ignoreConditionals) { if ((pc < start) || (pc > end)) @@ -373,13 +405,26 @@ if (ignoreConditionals) return true; - for (Map.Entry<Integer, Integer> entry : conditionalRanges.entrySet()) - { - if ((pc >= entry.getKey().intValue()) && pc <= entry.getValue().intValue()) - return false; - } - - return true; + return !inConditionalRange(pc); } + + public void foundAdd(int pc) { + if (addPC == 0) + addPC = pc; + else + addPC = -1; + } + + public int getStartPC() { + return start; + } + + public int getEndPC() { + return end; + } + + public int getAddPC() { + return addPC; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-03-16 01:52:55
|
Revision: 1006 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1006&view=rev Author: dbrosius Date: 2008-03-15 18:52:58 -0700 (Sat, 15 Mar 2008) Log Message: ----------- Initial checkin, WEM detector Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/WEM_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2008-03-15 06:17:22 UTC (rev 1005) +++ trunk/fb-contrib/etc/findbugs.xml 2008-03-16 01:52:58 UTC (rev 1006) @@ -312,6 +312,10 @@ speed="fast" reports="SCA_SUSPICIOUS_CLONE_ALGORITHM" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.WeakExceptionMessaging" + speed="fast" + reports="WEM_WEAK_EXCEPTION_MESSAGING" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -416,4 +420,5 @@ <BugPattern abbrev="JAO" type="JAO_JUNIT_ASSERTION_ODDITIES_INEXACT_DOUBLE" category="STYLE" experimental="true" /> <BugPattern abbrev="JAO" type="JAO_JUNIT_ASSERTION_ODDITIES_BOOLEAN_ASSERT" category="STYLE" experimental="true" /> <BugPattern abbrev="SCA" type="SCA_SUSPICIOUS_CLONE_ALGORITHM" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="WEM" type="WEM_WEAK_EXCEPTION_MESSAGING" category="STYLE" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2008-03-15 06:17:22 UTC (rev 1005) +++ trunk/fb-contrib/etc/messages.xml 2008-03-16 01:52:58 UTC (rev 1006) @@ -852,9 +852,22 @@ <![CDATA[ <p>looks for implementations of clone where an assignment is made to a field of the source object. It is likely that that store should have occurred on the cloned object, as - the clone operation is almost always considered read only.</p>]]> + the clone operation is almost always considered read only.</p> + <p>It is a fast detector</p> + ]]> </Details> </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.WeakExceptionMessaging"> + <Details> + <![CDATA[ + <p>looks for exceptions that are thrown with static strings as messages. Using static strings + doesn't differentiate one use of this method versus another, and so it may be difficult + to determine how this exception occurred without showing context.<p> + <p>It is a fast detector</p> + ]]> + </Details> + </Detector> <!-- BugPattern --> @@ -2206,6 +2219,19 @@ </Details> </BugPattern> + <BugPattern type="WEM_WEAK_EXCEPTION_MESSAGING"> + <ShortDescription>method throws exception with static message string</ShortDescription> + <LongDescription>method {1} throws exception with static message string</LongDescription> + <Details> + <![CDATA[ + <p>This method creates and throws an exception using a static string as the exceptions message. + Without any specific context of this particular exception invocation, such as the value of parameters, + key member variables, or local variables, it may be difficult to infer how this exception occurred. Consider + adding context to the exception message.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -2278,4 +2304,5 @@ <BugCode abbrev="CFS">Confusing Function Semantics</BugCode> <BugCode abbrev="JAO">JUnit Assertion Oddities</BugCode> <BugCode abbrev="SCA">Suspicious Clone Algorithm</BugCode> + <BugCode abbrev="WEM">Weak Exception Messaging</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/WEM_Sample.java =================================================================== --- trunk/fb-contrib/samples/WEM_Sample.java (rev 0) +++ trunk/fb-contrib/samples/WEM_Sample.java 2008-03-16 01:52:58 UTC (rev 1006) @@ -0,0 +1,16 @@ + +public class WEM_Sample +{ + public void badException (String s) + { + if (s.length() == 1) + throw new IllegalArgumentException("You stink"); + } + + public void goodException (String s) + { + if (s.length() == 1) + throw new IllegalArgumentException("You stink -->" + s); + } + +} Property changes on: trunk/fb-contrib/samples/WEM_Sample.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java 2008-03-16 01:52:58 UTC (rev 1006) @@ -0,0 +1,158 @@ +/* + * fb-contrib - Auxiliary detectors for Java programs + * Copyright (C) 2005-2008 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 java.util.BitSet; + +import org.apache.bcel.Constants; +import org.apache.bcel.Repository; +import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.ConstantString; +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; +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; + +public class WeakExceptionMessaging extends BytecodeScanningDetector { + + private static JavaClass exceptionClass; + static { + try { + exceptionClass = Repository.lookupClass("java/lang/Exception"); + } catch (ClassNotFoundException cnfe) { + exceptionClass = null; + } + } + + private BugReporter bugReporter; + private OpcodeStack stack; + + /** + * constructs a WEM detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ + public WeakExceptionMessaging(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** + * overrides the visitor to initialize and tear down the opcode stack + * + * @Param classContext the context object of the currently parsed class + */ + @Override + public void visitClassContext(ClassContext classContext) { + try { + if (exceptionClass != null) { + stack = new OpcodeStack(); + super.visitClassContext(classContext); + } + } finally { + stack = null; + } + } + + /** + * looks for methods that contain a ATHROW opcodes + * + * @param method the context object of the current method + * @return if the class uses throws + */ + public boolean prescreen(Method method) { + BitSet bytecodeSet = getClassContext().getBytecodeSet(method); + return (bytecodeSet != null) && (bytecodeSet.get(Constants.ATHROW)); + } + + /** + * overrides the visitor to prescreen the method to look for throws calls + * and only forward onto bytecode scanning if there + * + * @param obj the context object of the currently parsed code block + */ + @Override + public void visitCode(Code obj) { + if (prescreen(getMethod())) { + stack.resetForMethodEntry(this); + super.visitCode(obj); + } + } + + /** + * overrides the visitor to look for throws instructions using exceptions with + * static messages + * + * @param seen the opcode of the currently visited instruction + */ + @Override + public void sawOpcode(int seen) { + boolean allConstantStrings = false; + boolean sawConstant = false; + try { + if (seen == ATHROW) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + if (item.getUserValue() != null) { + bugReporter.reportBug(new BugInstance(this, "WEM_WEAK_EXCEPTION_MESSAGING", LOW_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } else if (seen == LDC) { + if (getConstantRefOperand() instanceof ConstantString) + sawConstant = true; + } else if (seen == INVOKESPECIAL) { + if ("<init>".equals(getNameConstantOperand())) { + String clsName = getClassConstantOperand(); + if (clsName.indexOf("Exception") >= 0) { + JavaClass exCls = Repository.lookupClass(clsName); + if (exCls.instanceOf(exceptionClass)) { + String sig = getSigConstantOperand(); + Type[] argTypes = Type.getArgumentTypes(sig); + for (int t = 0; t < argTypes.length; t++) { + if ("Ljava/lang/String;".equals(argTypes[t].getSignature())) { + int stackOffset = argTypes.length - t - 1; + if (stack.getStackDepth() > stackOffset) { + OpcodeStack.Item item = stack.getStackItem(stackOffset); + if (item.getUserValue() == null) + return; + } + } + } + allConstantStrings = true; + } + } + } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } finally { + stack.sawOpcode(this, seen); + if ((sawConstant || allConstantStrings) && (stack.getStackDepth() > 0)) { + OpcodeStack.Item item = stack.getStackItem(0); + item.setUserValue(Boolean.TRUE); + } + } + } +} Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-03-16 02:45:22
|
Revision: 1007 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1007&view=rev Author: dbrosius Date: 2008-03-15 19:45:28 -0700 (Sat, 15 Mar 2008) Log Message: ----------- don't report WEM when in static no arg methods Modified Paths: -------------- trunk/fb-contrib/samples/WEM_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java Modified: trunk/fb-contrib/samples/WEM_Sample.java =================================================================== --- trunk/fb-contrib/samples/WEM_Sample.java 2008-03-16 01:52:58 UTC (rev 1006) +++ trunk/fb-contrib/samples/WEM_Sample.java 2008-03-16 02:45:28 UTC (rev 1007) @@ -12,5 +12,10 @@ if (s.length() == 1) throw new IllegalArgumentException("You stink -->" + s); } + + public static void ok() + { + throw new RuntimeException("Wow"); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java 2008-03-16 01:52:58 UTC (rev 1006) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java 2008-03-16 02:45:28 UTC (rev 1007) @@ -92,9 +92,12 @@ */ @Override public void visitCode(Code obj) { - if (prescreen(getMethod())) { - stack.resetForMethodEntry(this); - super.visitCode(obj); + Method method = getMethod(); + if (!method.isStatic() || !method.getSignature().startsWith("()")) { + if (prescreen(getMethod())) { + stack.resetForMethodEntry(this); + super.visitCode(obj); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-04-02 03:13:17
|
Revision: 1015 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1015&view=rev Author: dbrosius Date: 2008-04-01 20:13:22 -0700 (Tue, 01 Apr 2008) Log Message: ----------- upgrade to use findbugs 1.3.3 as build reference Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/lib/asm-3.0.jar trunk/fb-contrib/lib/bcel.jar trunk/fb-contrib/lib/findbugs-ant.jar trunk/fb-contrib/lib/findbugs.jar Added Paths: ----------- trunk/fb-contrib/lib/asm-tree-3.0.jar Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2008-03-24 01:44:54 UTC (rev 1014) +++ trunk/fb-contrib/build.xml 2008-04-02 03:13:22 UTC (rev 1015) @@ -151,7 +151,7 @@ <mkdir dir="${basedir}/plugin"/> <copy file="${basedir}/fb-contrib-${fb-contrib.version}.jar" todir="${basedir}/plugin"/> - <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpath="${lib.dir}/findbugs-ant.jar;${lib.dir}/findbugs.jar;${lib.dir}/bcel.jar;${lib.dir}/dom4j-full.jar;${lib.dir}/asm-3.0.jar"/> + <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpath="${lib.dir}/findbugs-ant.jar;${lib.dir}/findbugs.jar;${lib.dir}/bcel.jar;${lib.dir}/dom4j-full.jar;${lib.dir}/asm-3.0.jar;${lib.dir}/asm-tree-3.0.jar"/> <findbugs output="xml" home="${basedir}" Modified: trunk/fb-contrib/lib/asm-3.0.jar =================================================================== (Binary files differ) Added: trunk/fb-contrib/lib/asm-tree-3.0.jar =================================================================== (Binary files differ) Property changes on: trunk/fb-contrib/lib/asm-tree-3.0.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/fb-contrib/lib/bcel.jar =================================================================== (Binary files differ) Modified: trunk/fb-contrib/lib/findbugs-ant.jar =================================================================== (Binary files differ) Modified: trunk/fb-contrib/lib/findbugs.jar =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-06-02 07:03:22
|
Revision: 1028 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1028&view=rev Author: dbrosius Date: 2008-06-02 00:03:29 -0700 (Mon, 02 Jun 2008) Log Message: ----------- Initial checkin of SCSS - not even close to working, yet. Modified Paths: -------------- trunk/fb-contrib/build.xml Added Paths: ----------- trunk/fb-contrib/samples/SCSS_Sample.java trunk/fb-contrib/samples/lib/servlet-api.jar trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousClusteredSessionSupport.java Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2008-06-01 21:04:33 UTC (rev 1027) +++ trunk/fb-contrib/build.xml 2008-06-02 07:03:29 UTC (rev 1028) @@ -46,6 +46,7 @@ <path id="fb-contrib.samples.classpath"> <pathelement location="${sampleslib.dir}/jsp-api.jar"/> <pathelement location="${sampleslib.dir}/junit.jar"/> + <pathelement location="${sampleslib.dir}/servlet-api.jar"/> </path> <mkdir dir="${classes.dir}/com"/> <mkdir dir="${classes.dir}/com/mebigfatguy"/> Added: trunk/fb-contrib/samples/SCSS_Sample.java =================================================================== --- trunk/fb-contrib/samples/SCSS_Sample.java (rev 0) +++ trunk/fb-contrib/samples/SCSS_Sample.java 2008-06-02 07:03:29 UTC (rev 1028) @@ -0,0 +1,13 @@ +import java.util.Set; + +import javax.servlet.http.HttpSession; + + +public class SCSS_Sample +{ + public void setChange(HttpSession session) + { + Set<String> ss = (Set<String>)session.getAttribute("mykeys"); + ss.add("Foo"); + } +} Property changes on: trunk/fb-contrib/samples/SCSS_Sample.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/fb-contrib/samples/lib/servlet-api.jar =================================================================== (Binary files differ) Property changes on: trunk/fb-contrib/samples/lib/servlet-api.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousClusteredSessionSupport.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousClusteredSessionSupport.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousClusteredSessionSupport.java 2008-06-02 07:03:29 UTC (rev 1028) @@ -0,0 +1,132 @@ +/* + * fb-contrib - Auxiliary detectors for Java programs + * Copyright (C) 2005-2008 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 java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.bcel.classfile.Code; + +import com.mebigfatguy.fbcontrib.utils.Integer14; +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; + +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 methods that access objects in http sessions, that are complex objects, + * modifies those objects, but does not call setAttribute to signify a change so that + * cluster replication can happen. + */ +public class SuspiciousClusteredSessionSupport extends BytecodeScanningDetector { + + private BugReporter bugReporter; + private OpcodeStack stack; + private Map<String, Integer> attributes; + private Set<String> changedAttributes; + private Map<Integer, String> savedAttributes; + + public SuspiciousClusteredSessionSupport(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + @Override + public void visitClassContext(ClassContext classContext) { + try { + stack = new OpcodeStack(); + attributes = new HashMap<String, Integer>(); + changedAttributes = new HashSet<String>(); + savedAttributes = new HashMap<Integer, String>(); + super.visitClassContext(classContext); + } finally { + stack = null; + attributes = null; + changedAttributes = null; + } + } + + @Override + public void visitCode(Code obj) { + stack.resetForMethodEntry(this); + attributes.clear(); + changedAttributes.clear(); + savedAttributes.clear(); + super.visitCode(obj); + } + + @Override + public void sawOpcode(int seen) { + String attributeName = null; + boolean sawGetAttribute = false; + try { + if (seen == INVOKEINTERFACE) { + String clsName = getClassConstantOperand(); + if ("javax.servlet.http.HttpSession".equals(clsName)) { + String methodName = getNameConstantOperand(); + if ("getAttribute".equals(methodName)) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + Object con = item.getConstant(); + if (con instanceof String) { + attributeName = (String)con; + attributes.put(attributeName, Integer14.valueOf(getPC())); + sawGetAttribute = true; + } + } + } else if ("setAttribute".equals(methodName)) { + if (stack.getStackDepth() > 1) { + OpcodeStack.Item item = stack.getStackItem(1); + Object con = item.getConstant(); + if (con instanceof String) { + attributeName = (String)con; + attributes.remove(attributeName); + } + } + } + } + } else if (((seen >= ALOAD_0) && (seen <= ALOAD_3)) || (seen == ALOAD)) { + if (stack.getStackDepth() > 0) { + int reg = RegisterUtils.getALoadReg(this, seen); + attributeName = savedAttributes.get(Integer14.valueOf(reg)); + sawGetAttribute = attributeName != null; + } + } else if (((seen >= ASTORE_0) && (seen <= ASTORE_3)) || (seen == ASTORE)) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + attributeName = (String)item.getUserValue(); + int reg = RegisterUtils.getAStoreReg(this, seen); + savedAttributes.put(Integer14.valueOf(reg), attributeName); + } + } + } finally { + stack.sawOpcode(this, seen); + if (sawGetAttribute) + { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + item.setUserValue(attributeName); + } + } + } + } +} \ No newline at end of file Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousClusteredSessionSupport.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-06-02 08:14:29
|
Revision: 1033 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1033&view=rev Author: dbrosius Date: 2008-06-02 01:14:37 -0700 (Mon, 02 Jun 2008) Log Message: ----------- add checking for array storing into an attribute Modified Paths: -------------- trunk/fb-contrib/samples/SCSS_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousClusteredSessionSupport.java Modified: trunk/fb-contrib/samples/SCSS_Sample.java =================================================================== --- trunk/fb-contrib/samples/SCSS_Sample.java 2008-06-02 08:03:33 UTC (rev 1032) +++ trunk/fb-contrib/samples/SCSS_Sample.java 2008-06-02 08:14:37 UTC (rev 1033) @@ -10,4 +10,10 @@ Set<String> ss = (Set<String>)session.getAttribute("mykeys"); ss.add("Foo"); } + + public void arrayChange(HttpSession session) + { + double[] d = (double[])session.getAttribute("mynums"); + d[3] = 0.0; + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousClusteredSessionSupport.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousClusteredSessionSupport.java 2008-06-02 08:03:33 UTC (rev 1032) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousClusteredSessionSupport.java 2008-06-02 08:14:37 UTC (rev 1033) @@ -137,6 +137,14 @@ } } } + } else if ((seen >= IASTORE) && (seen <= SASTORE)) { + if (stack.getStackDepth() > 2) { + OpcodeStack.Item item = stack.getStackItem(2); + attributeName = (String)item.getUserValue(); + if (attributeName != null) { + changedAttributes.put(attributeName, Integer14.valueOf(getPC())); + } + } } } 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...> - 2008-06-07 05:19:08
|
Revision: 1040 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1040&view=rev Author: dbrosius Date: 2008-06-06 22:19:13 -0700 (Fri, 06 Jun 2008) Log Message: ----------- get ready for 3.6.1 Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2008-06-07 04:48:44 UTC (rev 1039) +++ trunk/fb-contrib/build.xml 2008-06-07 05:19:13 UTC (rev 1040) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.7.0"/> + <property name="fb-contrib.version" value="3.6.1"/> <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 2008-06-07 04:48:44 UTC (rev 1039) +++ trunk/fb-contrib/etc/findbugs.xml 2008-06-07 05:19:13 UTC (rev 1040) @@ -318,7 +318,8 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousClusteredSessionSupport" speed="fast" - reports="SCSS_SUSPICIOUS_CLUSTERED_SESSION_SUPPORT" /> + reports="SCSS_SUSPICIOUS_CLUSTERED_SESSION_SUPPORT" + hidden="true" /> <!-- BugPattern --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-06-07 05:29:05
|
Revision: 1042 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1042&view=rev Author: dbrosius Date: 2008-06-06 22:29:13 -0700 (Fri, 06 Jun 2008) Log Message: ----------- go back to 3.7.0 dev Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2008-06-07 05:28:04 UTC (rev 1041) +++ trunk/fb-contrib/build.xml 2008-06-07 05:29:13 UTC (rev 1042) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.6.1"/> + <property name="fb-contrib.version" value="3.7.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 2008-06-07 05:28:04 UTC (rev 1041) +++ trunk/fb-contrib/etc/findbugs.xml 2008-06-07 05:29:13 UTC (rev 1042) @@ -318,8 +318,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousClusteredSessionSupport" speed="fast" - reports="SCSS_SUSPICIOUS_CLUSTERED_SESSION_SUPPORT" - hidden="true" /> + reports="SCSS_SUSPICIOUS_CLUSTERED_SESSION_SUPPORT" /> <!-- BugPattern --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-06-13 19:22:32
|
Revision: 1049 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1049&view=rev Author: dbrosius Date: 2008-06-13 12:07:03 -0700 (Fri, 13 Jun 2008) Log Message: ----------- add check for Calendar.after(date) Calendar.before(date) 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 2008-06-09 18:06:22 UTC (rev 1048) +++ trunk/fb-contrib/etc/findbugs.xml 2008-06-13 19:07:03 UTC (rev 1049) @@ -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" /> + 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" /> <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" @@ -406,6 +406,7 @@ <BugPattern abbrev="SPP" type="SPP_USELESS_TRINARY" category="PERFORMANCE" /> <BugPattern abbrev="SPP" type="SPP_SUSPECT_STRING_TEST" category="CORRECTNESS" /> <BugPattern abbrev="SPP" type="SPP_USE_STRINGBUILDER_LENGTH" category="PERFORMANCE" /> + <BugPattern abbrev="SPP" type="SPP_INVALID_CALENDAR_COMPARE" category="CORRECTNESS"/> <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-06-09 18:06:22 UTC (rev 1048) +++ trunk/fb-contrib/etc/messages.xml 2008-06-13 19:07:03 UTC (rev 1049) @@ -1994,6 +1994,18 @@ </Details> </BugPattern> + <BugPattern type="SPP_INVALID_CALENDAR_COMPARE"> + <ShortDescription>Method passes a non calendar object to Calendar.before or Calendar.after</ShortDescription> + <LongDescription>Method {1} passes a non calendar object to Calendar.before or Calendar.after</LongDescription> + <Details> + <![CDATA[ + <p>This method passes a non calendar object to the java.util.Calendar.after or java.util.Calendar.before methods. + Even though these methods take an Object as a parameter type, only Calendar type objects are supported, otherwise + false is returned</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 2008-06-09 18:06:22 UTC (rev 1048) +++ trunk/fb-contrib/samples/SPP_Sample.java 2008-06-13 19:07:03 UTC (rev 1049) @@ -1,5 +1,7 @@ import java.math.BigDecimal; import java.util.BitSet; +import java.util.Calendar; +import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -182,4 +184,9 @@ return null; } + + public boolean testCalBeforeAfter(Calendar c, Date d) + { + return c.after(d) || c.before(d); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2008-06-09 18:06:22 UTC (rev 1048) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2008-06-13 19:07:03 UTC (rev 1049) @@ -404,6 +404,17 @@ } } } + } else if ("java/util/Calendar".equals(className) + && ("after".equals(methodName) || "before".equals(methodName))) { + if (stack.getStackDepth() > 1) { + OpcodeStack.Item item = stack.getStackItem(0); + if (!"Ljava/util/Calendar;".equals(item.getSignature())) { + bugReporter.reportBug(new BugInstance(this, "SPP_INVALID_CALENDAR_COMPARE", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } } } 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. |
From: <dbr...@us...> - 2008-06-14 20:57:36
|
Revision: 1052 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1052&view=rev Author: dbrosius Date: 2008-06-14 13:57:44 -0700 (Sat, 14 Jun 2008) Log Message: ----------- up to 2008 Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/samples/AFBR_Sample.java Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2008-06-13 21:47:01 UTC (rev 1051) +++ trunk/fb-contrib/build.xml 2008-06-14 20:57:44 UTC (rev 1052) @@ -150,7 +150,7 @@ destdir="${javadoc.dir}" windowtitle="fb-contrib api"> <doctitle><![CDATA[<h1>fb-contrib javadoc</h1>]]></doctitle> - <bottom><![CDATA[<i>Copyright © 2005-2007 MeBigFatGuy.com. All Rights Reserved.</i>]]></bottom> + <bottom><![CDATA[<i>Copyright © 2005-2008 MeBigFatGuy.com. All Rights Reserved.</i>]]></bottom> </javadoc> </target> Modified: trunk/fb-contrib/samples/AFBR_Sample.java =================================================================== --- trunk/fb-contrib/samples/AFBR_Sample.java 2008-06-13 21:47:01 UTC (rev 1051) +++ trunk/fb-contrib/samples/AFBR_Sample.java 2008-06-14 20:57:44 UTC (rev 1052) @@ -2,7 +2,6 @@ import java.io.IOException; import java.io.InputStream; - public class AFBR_Sample { public int test1(boolean b) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-07-09 06:08:50
|
Revision: 1056 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1056&view=rev Author: dbrosius Date: 2008-07-08 23:08:56 -0700 (Tue, 08 Jul 2008) Log Message: ----------- look for myset.keySet().contains("foo") Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/samples/LEST_Sample.java trunk/fb-contrib/samples/SPP_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.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-07-05 05:28:32 UTC (rev 1055) +++ trunk/fb-contrib/etc/findbugs.xml 2008-07-09 06:08:56 UTC (rev 1056) @@ -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" /> + 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" /> <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" @@ -407,6 +407,7 @@ <BugPattern abbrev="SPP" type="SPP_SUSPECT_STRING_TEST" category="CORRECTNESS" /> <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="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-07-05 05:28:32 UTC (rev 1055) +++ trunk/fb-contrib/etc/messages.xml 2008-07-09 06:08:56 UTC (rev 1056) @@ -2006,6 +2006,16 @@ </Details> </BugPattern> + <BugPattern type="SPP_USE_CONTAINSKEY"> + <ShortDescription>Method calls keySet() just to call contains, use containsKey instead</ShortDescription> + <LongDescription>Method {1} calls keySet() just to call contains, use containsKey instead</LongDescription> + <Details> + <![CDATA[ + <p>This method calls mySet.keySet().contains("foo") when mySet.containsKey("foo") is simpler</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/LEST_Sample.java =================================================================== --- trunk/fb-contrib/samples/LEST_Sample.java 2008-07-05 05:28:32 UTC (rev 1055) +++ trunk/fb-contrib/samples/LEST_Sample.java 2008-07-09 06:08:56 UTC (rev 1056) @@ -58,4 +58,18 @@ throw iae; } } + + public void testLestFP3(String s) + { + double d; + try + { + d = Double.parseDouble(s); + } + catch (NumberFormatException nfe) + { + + } + throw new RuntimeException("ok"); + } } Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2008-07-05 05:28:32 UTC (rev 1055) +++ trunk/fb-contrib/samples/SPP_Sample.java 2008-07-09 06:08:56 UTC (rev 1056) @@ -4,6 +4,7 @@ import java.util.Date; import java.util.HashSet; import java.util.Iterator; +import java.util.Map; import java.util.Set; import java.util.StringTokenizer; @@ -189,4 +190,10 @@ { return c.after(d) || c.before(d); } + + public void testUseContainsKey(Map m) + { + if (m.keySet().contains("Foo")) + System.out.println("Yup"); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2008-07-05 05:28:32 UTC (rev 1055) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2008-07-09 06:08:56 UTC (rev 1056) @@ -173,6 +173,7 @@ } } else if (pc == ex.getHandlerPC()) { removePreviousHandlers(pc); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2008-07-05 05:28:32 UTC (rev 1055) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2008-07-09 06:08:56 UTC (rev 1056) @@ -469,6 +469,27 @@ } } } + } else if (seen == INVOKEINTERFACE) { + String className = getClassConstantOperand(); + if ("java/util/Map".equals(className)) { + String method = getNameConstantOperand(); + if ("keySet".equals(method)) { + userValue = "keySet"; + } + } else if ("java/util/Set".equals(className)) { + String method = getNameConstantOperand(); + if ("contains".equals(method)) { + if (stack.getStackDepth() >= 2) { + OpcodeStack.Item item = stack.getStackItem(1); + if ("keySet".equals(item.getUserValue())) { + bugReporter.reportBug(new BugInstance(this, "SPP_USE_CONTAINSKEY", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + } } } finally { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |