Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [717] trunk/fb-contrib (Page 2)
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-12-10 07:16:14
|
Revision: 717 http://svn.sourceforge.net/fb-contrib/?rev=717&view=rev Author: dbrosius Date: 2006-12-09 23:16:06 -0800 (Sat, 09 Dec 2006) Log Message: ----------- initial checkin - new SCII detector Added Paths: ----------- trunk/fb-contrib/samples/SCII_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java Added: trunk/fb-contrib/samples/SCII_Sample.java =================================================================== --- trunk/fb-contrib/samples/SCII_Sample.java (rev 0) +++ trunk/fb-contrib/samples/SCII_Sample.java 2006-12-10 07:16:06 UTC (rev 717) @@ -0,0 +1,33 @@ +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +public class SCII_Sample extends OverEndulgentParent implements MouseListener +{ + public void mouseClicked(MouseEvent arg0) { + // TODO Auto-generated method stub + + } +} + +class OverEndulgentParent +{ + public void mousePressed(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + + public void mouseReleased(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + + public void mouseEntered(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + + public void mouseExited(MouseEvent arg0) { + // TODO Auto-generated method stub + + } +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java 2006-12-10 07:16:06 UTC (rev 717) @@ -0,0 +1,120 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005-2006 Dave Brosius + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package com.mebigfatguy.fbcontrib.detect; + +import java.util.HashSet; +import java.util.Set; + +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; + +import edu.umd.cs.findbugs.BugInstance; +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.Detector; +import edu.umd.cs.findbugs.ba.ClassContext; + +/** + * looks for classes that implement interfaces by relying on methods being + * implemented in superclasses, even tho the superclass knows nothing about + * the interface being implemented by the child. + */ +public class SpoiledChildInterfaceImplementor implements Detector { + + private BugReporter bugReporter; + + /** + * constructs a SCII detector given the reporter to report bugs on + + * @param bugReporter the sync of bug reports + */ + public SpoiledChildInterfaceImplementor(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** looks for classes that implement interfaces but don't provide those methods + * + * @param classContext the context object of the currently parsed class + */ + public void visitClassContext(ClassContext classContext) { + try { + JavaClass cls = classContext.getJavaClass(); + + if (cls.isAbstract() || cls.isInterface()) + return; + + if ("java.lang.Object".equals(cls.getSuperclassName())) + return; + + JavaClass[] infs = cls.getInterfaces(); + if (infs.length > 0) { + Set<String> clsMethods = buildMethodSet(cls); + for (JavaClass inf : cls.getInterfaces()) { + Set<String> infMethods = buildMethodSet(inf); + if (infMethods.size() > 0) { + infMethods.removeAll(clsMethods); + if (infMethods.size() > 0) { + if (!cls.getSuperClass().implementationOf(inf)) { + BugInstance bi = new BugInstance(this, "SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR", NORMAL_PRIORITY) + .addClass(cls) + .addString("Implementing interface: " + inf.getClassName()) + .addString("Methods:"); + for (String nameSig : infMethods) + bi.addString("\t" + nameSig); + + bugReporter.reportBug(bi); + return; + } + } + } + } + } + + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } + } + + /** + * required for implementing the interface + */ + public void report() { + } + + /** + * builds a set of all non constructor or static initializer method/signatures + * + * @param cls the class to build the method set from + * @return a set of method names/signatures + */ + public Set<String> buildMethodSet(JavaClass cls) { + Set<String> methods = new HashSet<String>(); + + for (Method m : cls.getMethods()) { + String methodName = m.getName(); + if (!"<init>".equals(methodName) && !"<clinit>".equals(methodName)) { + methods.add(methodName + ":" + m.getSignature()); + } + } + + return methods; + } + + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-12 04:44:55
|
Revision: 721 http://svn.sourceforge.net/fb-contrib/?rev=721&view=rev Author: dbrosius Date: 2006-12-11 20:35:24 -0800 (Mon, 11 Dec 2006) Log Message: ----------- check for Float too Modified Paths: -------------- 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/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-12-10 10:18:38 UTC (rev 720) +++ trunk/fb-contrib/etc/messages.xml 2006-12-12 04:35:24 UTC (rev 721) @@ -1598,8 +1598,8 @@ <LongDescription>Method {1} compares a double to Double.NAN</LongDescription> <Details> <![CDATA[ - <p>This method compares a douhle to the constant Double.NaN. You should use - Double.isNaN(d) if a primitive; or d.isNaN() if a boxed double, instead.</p> + <p>This method compares a douhle or float to the constant Double.NaN or Float.NaN. You should use + Double.isNaN(d) or Float.isNaN(f) if a primitive; or d.isNaN() or f.isNaN() if a boxed double, instead.</p> ]]> </Details> </BugPattern> Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2006-12-10 10:18:38 UTC (rev 720) +++ trunk/fb-contrib/samples/SPP_Sample.java 2006-12-12 04:35:24 UTC (rev 721) @@ -39,6 +39,12 @@ System.out.println("It's a nan"); } + public void testNAN(float f) + { + if (f == Float.NaN) + System.out.println("It's a nan"); + } + public void testBigDecimal() { BigDecimal d = new BigDecimal(2.1); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-12-10 10:18:38 UTC (rev 720) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-12-12 04:35:24 UTC (rev 721) @@ -107,6 +107,20 @@ .addSourceLine(this)); } } + } else if (seen == FCMPL) { + if (stack.getStackDepth() > 1) { + OpcodeStack.Item item = stack.getStackItem(0); + Float f1 = (Float)item.getConstant(); + item = stack.getStackItem(1); + Float f2 = (Float)item.getConstant(); + + if (((f1 != null) && f1.isNaN()) || ((f2 != null) && f2.isNaN())) { + bugReporter.reportBug(new BugInstance(this, "SPP_USE_ISNAN", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } } else if (((seen >= ASTORE_0) && (seen < ASTORE_3)) || (seen == ASTORE)) { reg = RegisterUtils.getAStoreReg(this, seen); if (seen == lastOpcode) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-13 16:47:19
|
Revision: 727 http://svn.sourceforge.net/fb-contrib/?rev=727&view=rev Author: dbrosius Date: 2006-12-13 08:46:58 -0800 (Wed, 13 Dec 2006) Log Message: ----------- add check for StringBuffer("") Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/samples/SPP_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-12-13 05:37:35 UTC (rev 726) +++ trunk/fb-contrib/etc/findbugs.xml 2006-12-13 16:46:58 UTC (rev 727) @@ -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"/> + 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"/> <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" @@ -338,6 +338,7 @@ <BugPattern abbrev="SPP" type="SPP_STUTTERED_ASSIGNMENT" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_USE_ISNAN" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_USE_BIGDECIMAL_STRING_CTOR" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="SPP" type="SPP_STRINGBUFFER_WITH_EMPTY_STRING" category="PERFORMANCE" experimental="true" /> <BugPattern abbrev="BAS" type="BAS_BLOATED_ASSIGNMENT_SCOPE" category="PERFORMANCE" experimental="true" /> <BugPattern abbrev="SCII" type="SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR" category="STYLE" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-12-13 05:37:35 UTC (rev 726) +++ trunk/fb-contrib/etc/messages.xml 2006-12-13 16:46:58 UTC (rev 727) @@ -1616,6 +1616,18 @@ </Details> </BugPattern> + <BugPattern type="SPP_STRINGBUFFER_WITH_EMPTY_STRING"> + <ShortDescription>Method passes empty string to StringBuffer of StringBuilder constructor</ShortDescription> + <LongDescription>Method {1} passes empty string to StringBuffer of StringBuilder constructor</LongDescription> + <Details> + <![CDATA[ + <p>This method calls the StringBuffer of StringBuilder constructor passing in a constant empty string (""). + This is the same as calling the default constructor, but makes the code work harder. Consider passing in a + default size instead. + ]]> + </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 2006-12-13 05:37:35 UTC (rev 726) +++ trunk/fb-contrib/samples/SPP_Sample.java 2006-12-13 16:46:58 UTC (rev 727) @@ -49,4 +49,9 @@ { BigDecimal d = new BigDecimal(2.1); } + + public void testEmptySB() + { + StringBuffer sb = new StringBuffer(""); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-12-13 05:37:35 UTC (rev 726) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-12-13 16:46:58 UTC (rev 727) @@ -164,7 +164,7 @@ } } } - } + } } else if (seen == INVOKESPECIAL) { String className = getClassConstantOperand(); if ("java/lang/StringBuffer".equals(className) @@ -192,7 +192,16 @@ } } } - } + } else if ("(Ljava/lang/String;)V".equals(signature)) { + OpcodeStack.Item item = stack.getStackItem(0); + String con = (String)item.getConstant(); + if ("".equals(con)) { + bugReporter.reportBug(new BugInstance(this, "SPP_STRINGBUFFER_WITH_EMPTY_STRING", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } } } else if ("java/math/BigDecimal".equals(className)) { if (stack.getStackDepth() > 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-16 07:34:54
|
Revision: 730 http://svn.sourceforge.net/fb-contrib/?rev=730&view=rev Author: dbrosius Date: 2006-12-15 23:34:52 -0800 (Fri, 15 Dec 2006) Log Message: ----------- Convert use of OpcodeStack.getField to OpcodeStack.getXField. Switch FieldAnnotation usage to XField. Update findbugs.jar to 1.1 Modified Paths: -------------- trunk/fb-contrib/lib/findbugs.jar trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ParallelLists.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java Modified: trunk/fb-contrib/lib/findbugs.jar =================================================================== (Binary files differ) Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java 2006-12-14 06:40:36 UTC (rev 729) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java 2006-12-16 07:34:52 UTC (rev 730) @@ -36,6 +36,7 @@ import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.SourceLineAnnotation; import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XField; /** * looks for fields that are implementations of java.util.List, but that are used in a set-like fashion. @@ -130,14 +131,14 @@ String signature = getSigConstantOperand(); if (className.startsWith("java/util/") && className.endsWith("List")) { - FieldAnnotation fa = getFieldFromStack(stack, signature); - if (fa != null) { - String field = fa.getFieldName(); - FieldInfo fi = fieldsReported.get(field); + XField field = getFieldFromStack(stack, signature); + if (field != null) { + String fieldName = field.getName(); + FieldInfo fi = fieldsReported.get(fieldName); if (fi != null) { String methodInfo = methodName + signature; if (listMethods.contains(methodInfo)) - fieldsReported.remove(field); + fieldsReported.remove(fieldName); else if (setMethods.contains(methodInfo)) fi.addUse(getPC()); } @@ -146,19 +147,19 @@ } else if (seen == INVOKEVIRTUAL) { String className = getClassConstantOperand(); if (className.startsWith("java/util/") && className.endsWith("List")) { - FieldAnnotation fa = getFieldFromStack(stack, getSigConstantOperand()); - if (fa != null) { - String field = fa.getFieldName(); - fieldsReported.remove(field); + XField field = getFieldFromStack(stack, getSigConstantOperand()); + if (field != null) { + String fieldName = field.getName(); + fieldsReported.remove(fieldName); } } } else if (seen == ARETURN) { if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); - FieldAnnotation fa = item.getField(); - if (fa != null) { - String field = fa.getFieldName(); - fieldsReported.remove(field); + XField field = item.getXField(); + if (field != null) { + String fieldName = field.getName(); + fieldsReported.remove(fieldName); } } } @@ -176,11 +177,11 @@ * * @return the field annotation for the field whose method was executed */ - private FieldAnnotation getFieldFromStack(final OpcodeStack stk, final String signature) { + private XField getFieldFromStack(final OpcodeStack stk, final String signature) { int parmCount = Type.getArgumentTypes(signature).length; if (stk.getStackDepth() > parmCount) { OpcodeStack.Item itm = stk.getStackItem(parmCount); - return itm.getField(); + return itm.getXField(); } return null; } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2006-12-14 06:40:36 UTC (rev 729) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2006-12-16 07:34:52 UTC (rev 730) @@ -30,9 +30,9 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; -import edu.umd.cs.findbugs.FieldAnnotation; import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XField; /** * looks for for loops that iterate over a java.util.List using an integer index, and get, @@ -389,18 +389,18 @@ int seenReg = loopCollectionItem.getRegisterNumber(); if (seenReg >= 0) { - if (itm.getField() != null) + if (itm.getXField() != null) return true; int newReg = itm.getRegisterNumber(); if ((newReg >= 0) && (seenReg != newReg)) return true; } else { - FieldAnnotation seenField = loopCollectionItem.getField(); + XField seenField = loopCollectionItem.getXField(); if (seenField != null) { if (itm.getRegisterNumber() >= 0) return true; - FieldAnnotation newField = itm.getField(); - if ((newField != null) && (!newField.getFieldName().equals(seenField.getFieldName()))) + XField newField = itm.getXField(); + if ((newField != null) && (!newField.getName().equals(seenField.getName()))) return true; } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-12-14 06:40:36 UTC (rev 729) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-12-16 07:34:52 UTC (rev 730) @@ -29,6 +29,7 @@ import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.detect.DubiousListCollection.FieldInfo; import com.mebigfatguy.fbcontrib.utils.Integer14; import edu.umd.cs.findbugs.BugInstance; @@ -38,6 +39,7 @@ import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.SourceLineAnnotation; import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XField; /** * looks for private collection members, either static or instance, that are only initialized in @@ -274,9 +276,9 @@ int parmCount = Type.getArgumentTypes(signature).length; if (stack.getStackDepth() > parmCount) { OpcodeStack.Item item = stack.getStackItem(parmCount); - FieldAnnotation fa = item.getField(); - if (fa != null) { - collectionFields.remove(fa.getFieldName()); + XField field = item.getXField(); + if (field != null) { + collectionFields.remove(field.getName()); } else { int reg = item.getRegisterNumber(); if (reg >= 0) { @@ -300,9 +302,9 @@ case ARETURN: if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); - FieldAnnotation fa = item.getField(); - if (fa != null) { - collectionFields.remove(fa.getFieldName()); + XField field = item.getXField(); + if (field != null) { + collectionFields.remove(field.getName()); } } break; @@ -317,9 +319,9 @@ case GOTO_W: if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); - FieldAnnotation fa = item.getField(); - if (fa != null) { - collectionFields.remove(fa.getFieldName()); + XField field = item.getXField(); + if (field != null) { + collectionFields.remove(field.getName()); } } break; @@ -390,9 +392,9 @@ if (stack.getStackDepth() >= parmCount) { for (int i = 0; i < parmCount; i++) { OpcodeStack.Item item = stack.getStackItem(i); - FieldAnnotation fa = item.getField(); - if (fa != null) { - collectionFields.remove(fa.getFieldName()); + XField field = item.getXField(); + if (field != null) { + collectionFields.remove(field.getName()); } } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ParallelLists.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ParallelLists.java 2006-12-14 06:40:36 UTC (rev 729) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ParallelLists.java 2006-12-16 07:34:52 UTC (rev 730) @@ -32,9 +32,9 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; -import edu.umd.cs.findbugs.FieldAnnotation; import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XField; /** * looks for classes that maintain two or more lists or arrays associated one-for-one through the same index @@ -132,21 +132,21 @@ OpcodeStack.Item list =stack.getStackItem(1); int indexReg = index.getRegisterNumber(); - FieldAnnotation fa = list.getField(); + XField field = list.getXField(); - if ((indexReg >= 0) && (fa != null)) { - if (listFields.contains(fa.getFieldName())) { + if ((indexReg >= 0) && (field != null)) { + if (listFields.contains(field.getName())) { String f = indexToFieldMap.get(Integer14.valueOf(indexReg)); - if ((f != null) && (!f.equals(fa.getFieldName()))) { + if ((f != null) && (!f.equals(field.getName()))) { bugReporter.reportBug( new BugInstance( this, "PL_PARALLEL_LISTS", NORMAL_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(this, getPC())); - listFields.remove(fa.getFieldName()); + listFields.remove(field.getName()); indexToFieldMap.clear(); } else - indexToFieldMap.put(Integer14.valueOf(indexReg), fa.getFieldName()); + indexToFieldMap.put(Integer14.valueOf(indexReg), field.getName()); } } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java 2006-12-14 06:40:36 UTC (rev 729) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java 2006-12-16 07:34:52 UTC (rev 730) @@ -32,10 +32,11 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; -import edu.umd.cs.findbugs.FieldAnnotation; import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.SourceLineAnnotation; import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XFactory; +import edu.umd.cs.findbugs.ba.XField; /** * looks for classes that maintain collections or StringBuffer/StringBuilders in static member @@ -93,7 +94,7 @@ increasingMethods.add("put"); } private BugReporter bugReporter; - private Map<FieldAnnotation, SourceLineAnnotation> bloatableFields; + private Map<XField, SourceLineAnnotation> bloatableFields; private OpcodeStack stack; private String methodName; @@ -114,14 +115,14 @@ @Override public void visitClassContext(ClassContext classContext) { try { - bloatableFields = new HashMap<FieldAnnotation, SourceLineAnnotation>(); + bloatableFields = new HashMap<XField, SourceLineAnnotation>(); JavaClass cls = classContext.getJavaClass(); Field[] fields = cls.getFields(); for (Field f : fields) { if (f.isStatic()) { String sig = f.getSignature(); if (bloatableSigs.contains(sig)) { - bloatableFields.put(FieldAnnotation.fromBCELField(cls.getClassName(), f), null); + bloatableFields.put(XFactory.createXField(cls.getClassName(), f.getName(), f.getSignature(), f.isStatic()), null); } } } @@ -130,7 +131,7 @@ stack = new OpcodeStack(); super.visitClassContext(classContext); - for (Map.Entry<FieldAnnotation, SourceLineAnnotation> entry : bloatableFields.entrySet()) { + for (Map.Entry<XField, SourceLineAnnotation> entry : bloatableFields.entrySet()) { SourceLineAnnotation sla = entry.getValue(); if (sla != null) { bugReporter.reportBug(new BugInstance(this, "PMB_POSSIBLE_MEMORY_BLOAT", NORMAL_PRIORITY) @@ -193,16 +194,16 @@ int argCount = Type.getArgumentTypes(sig).length; if (stack.getStackDepth() > argCount) { OpcodeStack.Item itm = stack.getStackItem(argCount); - FieldAnnotation fa = itm.getField(); - if (fa != null) { - if (bloatableFields.containsKey(fa)) { + XField field = itm.getXField(); + if (field != null) { + if (bloatableFields.containsKey(field)) { String methodName = getNameConstantOperand(); if (decreasingMethods.contains(methodName)) { - bloatableFields.remove(fa); + bloatableFields.remove(field); } else if (increasingMethods.contains(methodName)) { - if (bloatableFields.get(fa) == null) { + if (bloatableFields.get(field) == null) { SourceLineAnnotation sla = SourceLineAnnotation.fromVisitedInstruction(this); - bloatableFields.put(fa, sla); + bloatableFields.put(field, sla); } } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java 2006-12-14 06:40:36 UTC (rev 729) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java 2006-12-16 07:34:52 UTC (rev 730) @@ -36,9 +36,9 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; -import edu.umd.cs.findbugs.FieldAnnotation; import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XField; /** * looks for calls of the same method on the same object when that object hasn't changed. @@ -199,13 +199,13 @@ } OpcodeStack.Item obj = stack.getStackItem(parmCount); int reg = obj.getRegisterNumber(); - FieldAnnotation fa = obj.getField(); + XField field = obj.getXField(); MethodCall mc; if (reg >= 0) { mc = localMethodCalls.get(Integer14.valueOf(reg)); - } else if (fa != null) { - mc = fieldMethodCalls.get(fa.getFieldName()); + } else if (field != null) { + mc = fieldMethodCalls.get(field.getName()); } else return; @@ -233,13 +233,13 @@ if (reg >= 0) { localMethodCalls.remove(Integer14.valueOf(reg)); } else { - fieldMethodCalls.remove(fa.getFieldName()); + fieldMethodCalls.remove(field.getName()); } } else { if (reg >= 0) { localMethodCalls.put(Integer14.valueOf(reg), new MethodCall(methodName, signature, parmConstants)); - } else if (fa != null) { - fieldMethodCalls.put(fa.getFieldName(), new MethodCall(methodName, signature, parmConstants)); + } else if (field != null) { + fieldMethodCalls.put(field.getName(), new MethodCall(methodName, signature, parmConstants)); } } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2006-12-14 06:40:36 UTC (rev 729) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2006-12-16 07:34:52 UTC (rev 730) @@ -39,6 +39,7 @@ import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.SourceLineAnnotation; import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XField; /** * looks for interfaces that ignore 508 compliance, including not using JLabel.setLabelFor, @@ -214,9 +215,9 @@ if ("setLabelFor".equals(methodName)) { if (stack.getStackDepth() > 1) { OpcodeStack.Item item = stack.getStackItem(1); - FieldAnnotation fa = item.getField(); - if (fa != null) - fieldLabels.remove(fa); + XField field = item.getXField(); + if (field != null) + fieldLabels.remove(field); else { int reg = item.getRegisterNumber(); if (reg >= 0) { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java 2006-12-14 06:40:36 UTC (rev 729) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java 2006-12-16 07:34:52 UTC (rev 730) @@ -32,9 +32,9 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; -import edu.umd.cs.findbugs.FieldAnnotation; import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XField; /** * Looks for use of iterators on synchronized collections built from the Collections class. @@ -202,9 +202,9 @@ if (reg >= 0) monitorObjects.add(Integer14.valueOf(reg)); else { - FieldAnnotation fa = item.getField(); - if (fa != null) - monitorObjects.add(fa.getFieldName()); + XField field = item.getXField(); + if (field != null) + monitorObjects.add(field.getName()); } } } else if (seen == MONITOREXIT) { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java 2006-12-14 06:40:36 UTC (rev 729) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java 2006-12-16 07:34:52 UTC (rev 730) @@ -33,10 +33,10 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; -import edu.umd.cs.findbugs.FieldAnnotation; import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.SourceLineAnnotation; import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XField; /** * looks for collections or arrays that hold objects that are unrelated thru class or @@ -179,22 +179,22 @@ regs.add(Integer14.valueOf(reg)); } } else { - FieldAnnotation fa = colItm.getField(); - if (fa == null) + XField field = colItm.getXField(); + if (field == null) return; - Set<SourceLineAnnotation> sla = memberSourceLineAnnotations.get(fa.getFieldName()); + Set<SourceLineAnnotation> sla = memberSourceLineAnnotations.get(field.getName()); if (sla == null) { sla = new HashSet<SourceLineAnnotation>(); - memberSourceLineAnnotations.put(fa.getFieldName(), sla); + memberSourceLineAnnotations.put(field.getName(), sla); } sla.add(SourceLineAnnotation.fromVisitedInstruction(this)); - Set<String> commonSupers = memberCollections.get(fa.getFieldName()); + Set<String> commonSupers = memberCollections.get(field.getName()); if (commonSupers != null) mergeItem(commonSupers, sla, addItm); else { commonSupers = new HashSet<String>(); - memberCollections.put(fa.getFieldName(), commonSupers); + memberCollections.put(field.getName(), commonSupers); addNewItem(commonSupers, addItm); } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java 2006-12-14 06:40:36 UTC (rev 729) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java 2006-12-16 07:34:52 UTC (rev 730) @@ -33,9 +33,9 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; -import edu.umd.cs.findbugs.FieldAnnotation; import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XField; /** * looks for uses of sets or maps where the key is an enum. In these cases, it is @@ -236,11 +236,11 @@ private boolean alreadyReported(int stackPos) { if (stack.getStackDepth() > stackPos) { OpcodeStack.Item item = stack.getStackItem(stackPos); - FieldAnnotation fa = item.getField(); - if (fa == null) + XField field = item.getXField(); + if (field == null) return false; else { - String fieldName = fa.getFieldName(); + String fieldName = field.getName(); boolean checked = checkedFields.contains(fieldName); checkedFields.add(fieldName); return checked; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-19 06:57:29
|
Revision: 737 http://svn.sourceforge.net/fb-contrib/?rev=737&view=rev Author: dbrosius Date: 2006-12-18 22:57:27 -0800 (Mon, 18 Dec 2006) Log Message: ----------- Initial checkin DWI detector: non functional at present Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/DWI_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-12-17 07:53:07 UTC (rev 736) +++ trunk/fb-contrib/etc/findbugs.xml 2006-12-19 06:57:27 UTC (rev 737) @@ -266,6 +266,10 @@ speed="fast" reports="SCI_SPOILED_CHILD_INTERFACE_IMPLEMENTOR" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.DeletingWhileIterating" + speed="fast" + reports="DWI_DELETING_WHILE_ITERATING" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -341,4 +345,5 @@ <BugPattern abbrev="SPP" type="SPP_STRINGBUFFER_WITH_EMPTY_STRING" category="PERFORMANCE" experimental="true" /> <BugPattern abbrev="BAS" type="BAS_BLOATED_ASSIGNMENT_SCOPE" category="PERFORMANCE" experimental="true" /> <BugPattern abbrev="SCII" type="SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR" category="STYLE" experimental="true" /> + <BugPattern abbrev="DWI" type="DWI_DELETING_WHILE_ITERATING" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-12-17 07:53:07 UTC (rev 736) +++ trunk/fb-contrib/etc/messages.xml 2006-12-19 06:57:27 UTC (rev 737) @@ -712,6 +712,17 @@ ]]> </Details> </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.DeletingWhileIterating"> + <Details> + <![CDATA[ + <p>looks for deletion of items from a collection using the remove method + of the collection at the same time that the collection is being iterated on. If + this occurs the iterator will become invalid and throw a ConcurrentModificationException. + Instead, the remove should be called on the iterator itself.</p> + ]]> + </Details> + </Detector> <!-- BugPattern --> @@ -1635,7 +1646,10 @@ <![CDATA[ <p>This method assigns a value to a variable in an outer scope compared to where the variable is actually used. Assuming this evaluation does not have side effects, the assignment can be moved into the inner scope (if block) - so that its execution time isn't taken up if the if guard is false.</p> + so that its execution time isn't taken up if the if guard is false. Care should be + taken however that the right hand side of the assignment does not contain side + effects that are required to happen, or that changes are not made further down that + will effect the execution of the assignment when done later on.</p> ]]> </Details> </BugPattern> @@ -1654,6 +1668,20 @@ </Details> </BugPattern> + <BugPattern type="DWI_DELETING_WHILE_ITERATING"> + <ShortDescription>Method deletes collection element while iterating</ShortDescription> + <LongDescription>Method {1} deletes collection element while iterating</LongDescription> + <Details> + <![CDATA[ + <p>This method removes items from a collection using the remove method of the collection, while + at the same time iterating across the collection. Doing this will invalidate the iterator, and further + user of it, will cause ConcurrentModificationExceptions to be thrown. To avoid this, the remove + method of the iterator should be used. + </p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -1715,4 +1743,5 @@ <BugCode abbrev="SPP">Sillyness Pot Pourri</BugCode> <BugCode abbrev="BAS">Bloated Assignment Scope</BugCode> <BugCode abbrev="SCII">Spoiled Child Interface Implementor</BugCode> + <BugCode abbrev="DWI">Deleting While Iterating</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/DWI_Sample.java =================================================================== --- trunk/fb-contrib/samples/DWI_Sample.java (rev 0) +++ trunk/fb-contrib/samples/DWI_Sample.java 2006-12-19 06:57:27 UTC (rev 737) @@ -0,0 +1,16 @@ +import java.util.Iterator; +import java.util.Set; + +public class DWI_Sample +{ + public void deleteOdds(Set<Integer> bagOInts) + { + Iterator<Integer> it = bagOInts.iterator(); + while (it.hasNext()) + { + Integer i = it.next(); + if ((i.intValue() & 0x01) == 1) + bagOInts.remove(i); + } + } +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-19 06:57:27 UTC (rev 737) @@ -0,0 +1,216 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005-2006 Dave Brosius + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package com.mebigfatguy.fbcontrib.detect; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.bcel.Repository; +import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.JavaClass; + +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; +import edu.umd.cs.findbugs.ba.XField; + +public class DeletingWhileIterating extends BytecodeScanningDetector +{ + private static JavaClass collectionClass; + private static JavaClass iteratorClass; + private static final Set<String> collectionMethods; + static { + try { + collectionClass = Repository.lookupClass("java.util.Collection"); + iteratorClass = Repository.lookupClass("java.util.Iterator"); + } catch (ClassNotFoundException cnfe) { + collectionClass = null; + iteratorClass = null; + } + + collectionMethods = new HashSet<String>(); + collectionMethods.add("entrySet()Ljava/lang/Set;"); + collectionMethods.add("keySet()Ljava/lang/Set;"); + collectionMethods.add("values()Ljava/lang/Collection;"); + } + + private BugReporter bugReporter; + private OpcodeStack stack; + private List<Set<Comparable>> collectionGroups; + private Map<Integer, Integer> iteratorToGroup; + + /** + * constructs a DWI detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ + public DeletingWhileIterating(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** + * implements the visitor to setup the opcode stack, and collectionGroups + * + * @param classContext the context object of the currently parsed class + */ + public void visitClassContext(ClassContext classContext) { + if ((collectionClass == null) || (iteratorClass == null)) + return; + + try { + stack = new OpcodeStack(); + collectionGroups = new ArrayList<Set<Comparable>>(); + iteratorToGroup = new HashMap<Integer, Integer>(); + super.visitClassContext(classContext); + } finally { + stack = null; + collectionGroups = null; + iteratorToGroup = null; + } + } + + /** + * implements the visitor to reset the stack and collectionGroups + * + * @param obj the context object of the currently parsed code block + */ + public void visitCode(Code obj) { + stack.resetForMethodEntry(this); + collectionGroups.clear(); + iteratorToGroup.clear(); + super.visitCode(obj); + } + + /** + * implements the visitor to look for deletes on collections that are being iterated + * + * @param seen the opcode of the currently parsed instruction + */ + public void sawOpcode(int seen) { + int groupId = -1; + + try { + if (seen == INVOKEINTERFACE) + { + String className = getClassConstantOperand(); + if (isCollection(className)) { + String methodName = getNameConstantOperand(); + String signature = getSigConstantOperand(); + String methodInfo = methodName + signature; + if (collectionMethods.contains(methodInfo)) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + groupId = findCollectionGroup(itm); + + } + } else if ("iterator()Ljava/util/Iterator;".equals(methodInfo)) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + groupId = findCollectionGroup(itm); + + } + } else if ("remove(Ljava/lang/Object;)Z".equals(methodInfo)) { + + } + } + } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + Integer id = (Integer)itm.getUserValue(); + if (id != null) { + int reg = RegisterUtils.getAStoreReg(this, seen); + + try { + if (itm.getJavaClass().implementationOf(iteratorClass)) { + iteratorToGroup.put(Integer14.valueOf(reg), id); + } else { + Set<Comparable> group = collectionGroups.get(id); + if (group != null) { + group.add(Integer14.valueOf(reg)); + } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } + } + } + + } + } finally { + stack.sawOpcode(this, seen); + if ((groupId >= 0) && (stack.getStackDepth() > 0)) { + OpcodeStack.Item itm = stack.getStackItem(0); + itm.setUserValue(Integer14.valueOf(groupId)); + } + + } + } + + private boolean isCollection(String className) { + try { + JavaClass cls = Repository.lookupClass(className); + return cls.implementationOf(collectionClass); + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + return false; + } + } + + private int findCollectionGroup(OpcodeStack.Item itm) { + Comparable groupElement = null; + + Integer id = (Integer)itm.getUserValue(); + if (id != null) + return id.intValue(); + + int reg = itm.getRegisterNumber(); + if (reg >= 0) + groupElement = Integer14.valueOf(reg); + else { + XField field = itm.getXField(); + if (field != null) { + groupElement = field.getName(); + } + } + + if (groupElement != null) { + int numGroups = collectionGroups.size(); + for (int i = 0; i < numGroups; i++) { + Set<? extends Comparable> group = collectionGroups.get(i); + if (group.contains(groupElement)) { + return i; + } + } + + Set<Comparable> group = new HashSet<Comparable>(); + group.add(groupElement); + collectionGroups.add(group); + return collectionGroups.size() - 1; + } + + return -1; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-19 08:19:27
|
Revision: 740 http://svn.sourceforge.net/fb-contrib/?rev=740&view=rev Author: dbrosius Date: 2006-12-19 00:19:21 -0800 (Tue, 19 Dec 2006) Log Message: ----------- doc Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2006-12-19 08:16:30 UTC (rev 739) +++ trunk/fb-contrib/htdocs/index.html 2006-12-19 08:19:21 UTC (rev 740) @@ -62,6 +62,11 @@ Looks for classes that implement interfaces by relying on methods being implemented in superclasses, even though the superclass knows nothing about the interface being implemented by the child.</li> + <li><b>[DWI] Deleting While Iterating</b><br/> + Looks for deletion of items from a collection using the remove method + of the collection at the same time that the collection is being iterated on. If + this occurs the iterator will become invalid and throw a ConcurrentModificationException. + Instead, the remove should be called on the iterator itself.</li </ul> </div> <hr/> Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-19 08:16:30 UTC (rev 739) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-19 08:19:21 UTC (rev 740) @@ -39,6 +39,12 @@ import edu.umd.cs.findbugs.ba.ClassContext; import edu.umd.cs.findbugs.ba.XField; +/** + * looks for deletion of items from a collection using the remove method + * of the collection at the same time that the collection is being iterated on. If + * this occurs the iterator will become invalid and throw a ConcurrentModificationException. + * Instead, the remove should be called on the iterator itself. + */ public class DeletingWhileIterating extends BytecodeScanningDetector { private static JavaClass collectionClass; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-22 18:55:27
|
Revision: 751 http://svn.sourceforge.net/fb-contrib/?rev=751&view=rev Author: dbrosius Date: 2006-12-22 10:55:26 -0800 (Fri, 22 Dec 2006) Log Message: ----------- add @Override annotations Modified Paths: -------------- trunk/fb-contrib/samples/AOM_Sample.java trunk/fb-contrib/samples/COM_Sample.java trunk/fb-contrib/samples/ISB_Sample.java trunk/fb-contrib/samples/NRTL_Sample.java trunk/fb-contrib/samples/RMC_Sample.java trunk/fb-contrib/samples/STS_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SluggishGui.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java Modified: trunk/fb-contrib/samples/AOM_Sample.java =================================================================== --- trunk/fb-contrib/samples/AOM_Sample.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/samples/AOM_Sample.java 2006-12-22 18:55:26 UTC (rev 751) @@ -13,6 +13,7 @@ public abstract class AOM_Sample extends AOM_Super { + @Override public abstract void test1(); public abstract void test2(); } Modified: trunk/fb-contrib/samples/COM_Sample.java =================================================================== --- trunk/fb-contrib/samples/COM_Sample.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/samples/COM_Sample.java 2006-12-22 18:55:26 UTC (rev 751) @@ -24,10 +24,12 @@ public static class Derived extends COM_Sample { + @Override public void test1() { } + @Override public Set<String> test3(String a, String b, String c) { Set<String> ss = new HashSet<String>(); @@ -37,6 +39,7 @@ return ss; } + @Override public String test2(int i) { return String.valueOf(i); Modified: trunk/fb-contrib/samples/ISB_Sample.java =================================================================== --- trunk/fb-contrib/samples/ISB_Sample.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/samples/ISB_Sample.java 2006-12-22 18:55:26 UTC (rev 751) @@ -59,6 +59,7 @@ return sb.toString(); } + @Override public String toString() { String a = System.getProperty("foo"); Modified: trunk/fb-contrib/samples/NRTL_Sample.java =================================================================== --- trunk/fb-contrib/samples/NRTL_Sample.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/samples/NRTL_Sample.java 2006-12-22 18:55:26 UTC (rev 751) @@ -10,6 +10,7 @@ sample = s; } + @Override public int doStartTag() throws JspException { try { sample += Math.random(); @@ -25,6 +26,7 @@ sample2 = s; } + @Override public int doEndTag() { return EVAL_PAGE; } Modified: trunk/fb-contrib/samples/RMC_Sample.java =================================================================== --- trunk/fb-contrib/samples/RMC_Sample.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/samples/RMC_Sample.java 2006-12-22 18:55:26 UTC (rev 751) @@ -21,6 +21,7 @@ int j = bb.getInt(); } + @Override public boolean equals(Object o) { RMC_Sample rmc = (RMC_Sample)o; Modified: trunk/fb-contrib/samples/STS_Sample.java =================================================================== --- trunk/fb-contrib/samples/STS_Sample.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/samples/STS_Sample.java 2006-12-22 18:55:26 UTC (rev 751) @@ -30,6 +30,7 @@ c = calc; } + @Override public void run() { synchronized(c) @@ -51,6 +52,7 @@ { int total; + @Override public void run() { synchronized(this) Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-22 18:55:26 UTC (rev 751) @@ -327,6 +327,7 @@ * * @returns a string representation */ + @Override public String toString() { return "Start=" + startLocation + " Finish=" + finishLocation + " Loop=" + isLoop + " Loads=" + loads + " Stores=" + stores; } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java 2006-12-22 18:55:26 UTC (rev 751) @@ -118,6 +118,7 @@ * * @param seen the opcode of the currently parsed instruction */ + @Override public void sawOpcode(int seen) { try { stack.mergeJumps(this); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java 2006-12-22 18:55:26 UTC (rev 751) @@ -100,6 +100,7 @@ * * @param obj the method object for the currently parsed method */ + @Override public void visitMethod(Method obj) { curMethodInfo = obj.getName() + ":" + obj.getSignature(); } @@ -109,6 +110,7 @@ * * @param obj the code object of the currently parsed method */ + @Override public void visitCode(Code obj) { Method m = getMethod(); if (!m.isPublic() && !m.isProtected() && !m.isAbstract()) Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-22 18:55:26 UTC (rev 751) @@ -84,6 +84,7 @@ * * @param classContext the context object of the currently parsed class */ + @Override public void visitClassContext(ClassContext classContext) { if ((collectionClass == null) || (iteratorClass == null)) return; @@ -107,6 +108,7 @@ * * @param obj the context object of the currently parsed code block */ + @Override public void visitCode(Code obj) { stack.resetForMethodEntry(this); collectionGroups.clear(); @@ -120,6 +122,7 @@ * * @param seen the opcode of the currently parsed instruction */ + @Override public void sawOpcode(int seen) { int groupId = -1; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-12-22 18:55:26 UTC (rev 751) @@ -115,6 +115,7 @@ * * @param obj the context object of the currently parsed method */ + @Override public void visitMethod(Method obj) { if (localizableFields.size() == 0) return; @@ -172,6 +173,7 @@ * * @param seen the opcode of the currently visited instruction */ + @Override public void sawOpcode(int seen) { if ((seen == GETFIELD) || (seen == PUTFIELD)) { String fieldName = getNameConstantOperand(); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2006-12-22 18:55:26 UTC (rev 751) @@ -50,6 +50,7 @@ * * @param classContext the context object of the currently parsed class */ + @Override public void visitClassContext(ClassContext classContext) { try { stack = new OpcodeStack(); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java 2006-12-22 18:55:26 UTC (rev 751) @@ -52,6 +52,12 @@ this.bugReporter = bugReporter; } + /** + * implements the visitor to reset the stack and jdbc locals + * + * @param classContext the context object of the currently parsed class + */ + @Override public void visitClassContext(ClassContext classContext) { stack = new OpcodeStack(); jdbcLocals = new HashMap<Integer, Integer>(); @@ -81,6 +87,7 @@ } } + @Override public void sawOpcode(int seen) { boolean tosIsJDBC = false; try { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java 2006-12-22 18:55:26 UTC (rev 751) @@ -92,6 +92,7 @@ * * @param seen the opcode of the currently parsed instruction */ + @Override public void sawOpcode(int seen) { Integer tosIsPriority = null; try { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java 2006-12-22 18:55:26 UTC (rev 751) @@ -126,6 +126,7 @@ * * @param classContext the context object of the currently visited class */ + @Override public void visitClassContext(ClassContext classContext) { try { stack = new OpcodeStack(); @@ -146,6 +147,7 @@ * * @param obj the context object of the currently parsed code block */ + @Override public void visitCode(Code obj) { stack.resetForMethodEntry(this); localMethodCalls.clear(); @@ -164,6 +166,7 @@ * * @param seen the opcode of the currently parsed instruction */ + @Override public void sawOpcode(int seen) { try { stack.mergeJumps(this); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-12-22 18:55:26 UTC (rev 751) @@ -47,6 +47,7 @@ this.bugReporter = bugReporter; } + @Override public void visitClassContext(ClassContext classContext) { try { stack = new OpcodeStack(); @@ -61,6 +62,7 @@ * * @param obj the context object for the currently parsed Code */ + @Override public void visitCode(Code obj) { stack.resetForMethodEntry(this); lastOpcode = -1; @@ -73,6 +75,7 @@ * * @param seen the opcode of the currently parsed instruction */ + @Override public void sawOpcode(int seen) { int reg = -1; try { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java 2006-12-22 18:55:26 UTC (rev 751) @@ -110,6 +110,7 @@ super.visitMethod(obj); } + @Override public void visitField(Field obj) { if (state == COLLECT) { Type t = obj.getType(); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SluggishGui.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SluggishGui.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SluggishGui.java 2006-12-22 18:55:26 UTC (rev 751) @@ -181,6 +181,7 @@ * * @param seen the currently parsed opcode */ + @Override public void sawOpcode(int seen) { if (methodReported) return; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2006-12-22 18:55:26 UTC (rev 751) @@ -47,6 +47,7 @@ this.bugReporter = bugReporter; } + @Override public void visitClassContext(ClassContext classContext) { try { JavaClass cls = classContext.getJavaClass(); @@ -66,6 +67,7 @@ } } + @Override public void visitCode(Code obj) { String methodName = getMethodName(); String methodSig = getMethodSig(); @@ -90,6 +92,7 @@ } } + @Override public void sawOpcode(int seen) { try { if (indeterminate) Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java 2006-12-22 18:55:26 UTC (rev 751) @@ -62,6 +62,7 @@ * * @param classContext the context object of the currently parsed class */ + @Override public void visitClassContext(ClassContext classContext) { try { currentClass = classContext.getJavaClass(); @@ -138,6 +139,7 @@ * * @param seen the opcode of the currently parsed instruction */ + @Override public void sawOpcode(int seen) { try { stack.mergeJumps(this); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java 2006-12-22 18:55:26 UTC (rev 751) @@ -71,6 +71,7 @@ * * @param classContext the context object for the currently parsed class */ + @Override public void visitClassContext(ClassContext classContext) { try { JavaClass cls = classContext.getJavaClass(); @@ -94,6 +95,7 @@ * * @param obj the context object for the currently parsed method */ + @Override public void visitMethod(Method obj) { stack.resetForMethodEntry(this); methodReported = false; @@ -101,6 +103,7 @@ super.visitMethod(obj); } + @Override public void sawOpcode(int seen) { Boolean sawEnumCollectionCreation = null; //true - enum, false - nonenum try { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java 2006-12-22 18:23:27 UTC (rev 750) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java 2006-12-22 18:55:26 UTC (rev 751) @@ -64,6 +64,7 @@ * * @param classContext the context object of the currently parsed class */ + @Override public void visitClassContext(ClassContext classContext) { if (collectionClass == null) { if (ex != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-28 22:18:41
|
Revision: 764 http://svn.sourceforge.net/fb-contrib/?rev=764&view=rev Author: dbrosius Date: 2006-12-28 14:18:31 -0800 (Thu, 28 Dec 2006) Log Message: ----------- prepare for release 3.0.5 Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2006-12-26 02:44:03 UTC (rev 763) +++ trunk/fb-contrib/build.xml 2006-12-28 22:18:31 UTC (rev 764) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.1.0"/> + <property name="fb-contrib.version" value="3.0.5"/> <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 2006-12-26 02:44:03 UTC (rev 763) +++ trunk/fb-contrib/etc/findbugs.xml 2006-12-28 22:18:31 UTC (rev 764) @@ -252,23 +252,28 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparatorReturnValues" speed="fast" - reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES"/> + reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" + disabled="true" /> <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"/> + reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING" + disabled="true" /> <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" - reports="BAS_BLOATED_ASSIGNMENT_SCOPE" /> + reports="BAS_BLOATED_ASSIGNMENT_SCOPE" + disabled="true" /> <Detector class="com.mebigfatguy.fbcontrib.detect.SpoiledChildInterfaceImplementor" speed="fast" - reports="SCI_SPOILED_CHILD_INTERFACE_IMPLEMENTOR" /> + reports="SCI_SPOILED_CHILD_INTERFACE_IMPLEMENTOR" + disabled="true" /> <Detector class="com.mebigfatguy.fbcontrib.detect.DeletingWhileIterating" speed="fast" - reports="DWI_DELETING_WHILE_ITERATING" /> + reports="DWI_DELETING_WHILE_ITERATING" + disabled="true" /> <!-- BugPattern --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-05 06:22:56
|
Revision: 773 http://svn.sourceforge.net/fb-contrib/?rev=773&view=rev Author: dbrosius Date: 2007-01-04 22:22:56 -0800 (Thu, 04 Jan 2007) Log Message: ----------- get back to 3.2 dev, including adding check for calling .equals(Object o) on an enum Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/samples/SPP_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2007-01-05 05:42:40 UTC (rev 772) +++ trunk/fb-contrib/build.xml 2007-01-05 06:22:56 UTC (rev 773) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.0.7"/> + <property name="fb-contrib.version" value="3.1.0"/> <target name="clean" description="removes all generated collateral"> <delete dir="${classes.dir}"/> Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-01-05 05:42:40 UTC (rev 772) +++ trunk/fb-contrib/etc/findbugs.xml 2007-01-05 06:22:56 UTC (rev 773) @@ -252,28 +252,23 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparatorReturnValues" speed="fast" - reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" - disabled="true" /> + reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" /> <Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri" speed="fast" - reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING" - disabled="true" /> + reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM" /> <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" - reports="BAS_BLOATED_ASSIGNMENT_SCOPE" - disabled="true" /> + reports="BAS_BLOATED_ASSIGNMENT_SCOPE" /> <Detector class="com.mebigfatguy.fbcontrib.detect.SpoiledChildInterfaceImplementor" speed="fast" - reports="SCI_SPOILED_CHILD_INTERFACE_IMPLEMENTOR" - disabled="true" /> + reports="SCI_SPOILED_CHILD_INTERFACE_IMPLEMENTOR" /> <Detector class="com.mebigfatguy.fbcontrib.detect.DeletingWhileIterating" speed="fast" - reports="DWI_DELETING_WHILE_ITERATING" - disabled="true" /> + reports="DWI_DELETING_WHILE_ITERATING" /> <!-- BugPattern --> @@ -348,6 +343,7 @@ <BugPattern abbrev="SPP" type="SPP_USE_ISNAN" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_USE_BIGDECIMAL_STRING_CTOR" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_STRINGBUFFER_WITH_EMPTY_STRING" category="PERFORMANCE" experimental="true" /> + <BugPattern abbrev="SPP" type="SPP_EQUALS_ON_ENUM" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="BAS" type="BAS_BLOATED_ASSIGNMENT_SCOPE" category="PERFORMANCE" experimental="true" /> <BugPattern abbrev="SCII" type="SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR" category="STYLE" experimental="true" /> <BugPattern abbrev="DWI" type="DWI_DELETING_WHILE_ITERATING" category="CORRECTNESS" experimental="true" /> Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-01-05 05:42:40 UTC (rev 772) +++ trunk/fb-contrib/etc/messages.xml 2007-01-05 06:22:56 UTC (rev 773) @@ -1640,6 +1640,18 @@ </Details> </BugPattern> + <BugPattern type="SPP_EQUALS_ON_ENUM"> + <ShortDescription>Method calls equals on an enum instance</ShortDescription> + <LongDescription>Method {1} calls equals on an enum instance</LongDescription> + <Details> + <![CDATA[ + <p>This method calls the equals(Object) method on an enum instance. Since enums values are singletons, + you can use == to safely compare two enum values. In fact, the implementation for Enum.equals does just + that.</p> + ]]> + </Details> + </BugPattern> + <BugPattern type="BAS_BLOATED_ASSIGNMENT_SCOPE"> <ShortDescription>Method assigns a variable in a larger scope then is needed</ShortDescription> <LongDescription>Method {1} assigns a variable in a larger scope then is needed</LongDescription> Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2007-01-05 05:42:40 UTC (rev 772) +++ trunk/fb-contrib/samples/SPP_Sample.java 2007-01-05 06:22:56 UTC (rev 773) @@ -6,6 +6,8 @@ private static final double pi = 3.14; private static final double e = 2.72; + static enum Flap { Smack, Jack }; + public void testSPPBitSet(BitSet b) { b.set(-1); @@ -54,4 +56,10 @@ { StringBuffer sb = new StringBuffer(""); } + + public void equalsOnEnum(Flap f) + { + if (f.equals(Flap.Jack)) + System.out.println("Flap Jacks"); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-01-05 05:42:40 UTC (rev 772) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-01-05 06:22:56 UTC (rev 773) @@ -18,8 +18,10 @@ */ package com.mebigfatguy.fbcontrib.detect; +import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.ConstantDouble; +import org.apache.bcel.classfile.JavaClass; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; @@ -167,6 +169,18 @@ } } } + } else if ("equals(Ljava/lang/Object;)Z".equals(methodName + getSigConstantOperand())) { + try { + JavaClass cls = Repository.lookupClass(className); + if (cls.isEnum()) { + bugReporter.reportBug(new BugInstance(this, "SPP_EQUALS_ON_ENUM", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } } } else if (seen == INVOKESPECIAL) { String className = getClassConstantOperand(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-08 18:54:37
|
Revision: 774 http://svn.sourceforge.net/fb-contrib/?rev=774&view=rev Author: dbrosius Date: 2007-01-08 10:54:33 -0800 (Mon, 08 Jan 2007) Log Message: ----------- 1630677 - Don't report SMII on synthetic methods Modified Paths: -------------- trunk/fb-contrib/samples/SMII_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticMethodInstanceInvocation.java Modified: trunk/fb-contrib/samples/SMII_Sample.java =================================================================== --- trunk/fb-contrib/samples/SMII_Sample.java 2007-01-05 06:22:56 UTC (rev 773) +++ trunk/fb-contrib/samples/SMII_Sample.java 2007-01-08 18:54:33 UTC (rev 774) @@ -4,6 +4,8 @@ public class SMII_Sample { + private Inner i = new Inner(); + public static void static_empty() { } @@ -47,4 +49,15 @@ { String name = Object.class.getName(); } + + public void avoidGeneratedMethods(final Inner inner) + { + inner.next = null; + } + + public static class Inner + { + private Inner next; + + } } \ No newline at end of file Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticMethodInstanceInvocation.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticMethodInstanceInvocation.java 2007-01-05 06:22:56 UTC (rev 773) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticMethodInstanceInvocation.java 2007-01-08 18:54:33 UTC (rev 774) @@ -110,19 +110,22 @@ } if ((seen == INVOKESTATIC) && (popStack.size() > 0)) { - PopInfo pInfo = popStack.get(0); - Type[] args = Type.getArgumentTypes(getSigConstantOperand()); - if ((args.length > 0) || (pInfo.popPC == (getPC() - 1))) { - if (args.length == (stack.getStackDepth() - pInfo.popDepth)) { - if (classDefinesStaticMethod(pInfo.popSignature.substring(1, pInfo.popSignature.length() - 1))) { - bugReporter.reportBug(new BugInstance(this, "SMII_STATIC_METHOD_INSTANCE_INVOCATION", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); - popStack.clear(); - } - } - } + String method = getNameConstantOperand(); + if (method.indexOf('$') < 0) { + PopInfo pInfo = popStack.get(0); + Type[] args = Type.getArgumentTypes(getSigConstantOperand()); + if ((args.length > 0) || (pInfo.popPC == (getPC() - 1))) { + if (args.length == (stack.getStackDepth() - pInfo.popDepth)) { + if (classDefinesStaticMethod(pInfo.popSignature.substring(1, pInfo.popSignature.length() - 1))) { + bugReporter.reportBug(new BugInstance(this, "SMII_STATIC_METHOD_INSTANCE_INVOCATION", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + popStack.clear(); + } + } + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-09 05:01:56
|
Revision: 775 http://svn.sourceforge.net/fb-contrib/?rev=775&view=rev Author: dbrosius Date: 2007-01-08 21:01:52 -0800 (Mon, 08 Jan 2007) Log Message: ----------- get ready for 3.0.8 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-01-08 18:54:33 UTC (rev 774) +++ trunk/fb-contrib/build.xml 2007-01-09 05:01:52 UTC (rev 775) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.1.0"/> + <property name="fb-contrib.version" value="3.0.8"/> <target name="clean" description="removes all generated collateral"> <delete dir="${classes.dir}"/> Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-01-08 18:54:33 UTC (rev 774) +++ trunk/fb-contrib/etc/findbugs.xml 2007-01-09 05:01:52 UTC (rev 775) @@ -252,23 +252,28 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparatorReturnValues" speed="fast" - reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" /> + reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" + disabled="true" /> <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" /> + 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" + disabled="true" /> <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" - reports="BAS_BLOATED_ASSIGNMENT_SCOPE" /> + reports="BAS_BLOATED_ASSIGNMENT_SCOPE" + disabled="true" /> <Detector class="com.mebigfatguy.fbcontrib.detect.SpoiledChildInterfaceImplementor" speed="fast" - reports="SCI_SPOILED_CHILD_INTERFACE_IMPLEMENTOR" /> + reports="SCI_SPOILED_CHILD_INTERFACE_IMPLEMENTOR" + disabled="true" /> <Detector class="com.mebigfatguy.fbcontrib.detect.DeletingWhileIterating" speed="fast" - reports="DWI_DELETING_WHILE_ITERATING" /> + reports="DWI_DELETING_WHILE_ITERATING" + disabled="true" /> <!-- BugPattern --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-21 03:23:58
|
Revision: 778 http://svn.sourceforge.net/fb-contrib/?rev=778&view=rev Author: dbrosius Date: 2007-01-20 19:23:57 -0800 (Sat, 20 Jan 2007) Log Message: ----------- Add NAB check for Boxed.valueOf(myString).boxedValue() 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-01-09 07:49:30 UTC (rev 777) +++ trunk/fb-contrib/etc/findbugs.xml 2007-01-21 03:23:57 UTC (rev 778) @@ -115,7 +115,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessAutoboxing" speed="fast" - reports="NAB_NEEDLESS_AUTOBOXING" /> + reports="NAB_NEEDLESS_AUTOBOXING_CTOR,NAB_NEEDLESS_AUTOBOXING_VALUEOF,NAB_NEEDLESS_AUTOBOXING_PARSE" /> <Detector class="com.mebigfatguy.fbcontrib.detect.UnnecessaryStoreBeforeReturn" speed="fast" @@ -299,7 +299,9 @@ <BugPattern abbrev="AFBR" type="AFBR_ABNORMAL_FINALLY_BLOCK_RETURN" category="CORRECTNESS" /> <BugPattern abbrev="SMII" type="SMII_STATIC_METHOD_INSTANCE_INVOCATION" category="STYLE" /> <BugPattern abbrev="STS" type="STS_SPURIOUS_THREAD_STATES" category="MT_CORRECTNESS" /> - <BugPattern abbrev="NAB" type="NAB_NEEDLESS_AUTOBOXING" category="PERFORMANCE" /> + <BugPattern abbrev="NAB" type="NAB_NEEDLESS_AUTOBOXING_CTOR" category="PERFORMANCE" /> + <BugPattern abbrev="NAB" type="NAB_NEEDLESS_AUTOBOXING_VALUEOF" category="PERFORMANCE" /> + <BugPattern abbrev="NAB" type="NAB_NEEDLESS_AUTOBOXING_PARSE" 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-01-09 07:49:30 UTC (rev 777) +++ trunk/fb-contrib/etc/messages.xml 2007-01-21 03:23:57 UTC (rev 778) @@ -307,6 +307,9 @@ <li>new Double(Double)</li> </ul> </p> + <p>It also looks for calls to BoxedClass.valueOf(x) where X is already a Boxed class</p> + <p>It also looks for calls to BoxedClass.valueOf(myString).boxedValue(), When instead it is + simpler to use BoxedClass.parseBoxed(myString)</p> <p>It is a fast detector</p> ]]> </Details> @@ -1001,7 +1004,7 @@ </Details> </BugPattern> - <BugPattern type="NAB_NEEDLESS_AUTOBOXING"> + <BugPattern type="NAB_NEEDLESS_AUTOBOXING_CTOR"> <ShortDescription>method passes primitive wrapper to same primitive wrapper constructor</ShortDescription> <LongDescription>method {1} passes primitive wrapper to same primitive wrapper constructor</LongDescription> <Details> @@ -1014,6 +1017,32 @@ </Details> </BugPattern> + <BugPattern type="NAB_NEEDLESS_AUTOBOXING_VALUEOF"> + <ShortDescription>method passes primitive wrapper to Wrapper class valueOf method</ShortDescription> + <LongDescription>method {1} passes primitive wrapper to Wrapper class valueOf method</LongDescription> + <Details> + <![CDATA[ + <p>This method passes a wrapped primitive object to the same class's .valueOf method. + Since wrapper classes are immutable, you can just use the original object, rather + than calling valueOf to create a new one. This code works because of an abuse of autoboxing. + </p> + ]]> + </Details> + </BugPattern> + + <BugPattern type="NAB_NEEDLESS_AUTOBOXING_PARSE"> + <ShortDescription>method converts String to primitive using excessive autoboxing</ShortDescription> + <LongDescription>method {1} converts String to primitive using excessive autoboxing</LongDescription> + <Details> + <![CDATA[ + <p>This method passes a String to a wrapped primitive object's valueOf method, which in turn calls + the boxedValue() method to convert to a primitive. When it is desired to convert from a String + to a primitive value, it is simpler to use the BoxedPrimitive.parseBoxedPrimitive(myString) + method. </p> + ]]> + </Details> + </BugPattern> + <BugPattern type="USBR_UNNECESSARY_STORE_BEFORE_RETURN"> <ShortDescription>method stores return result in local before immediately returning it</ShortDescription> <LongDescription>method {1} stores return result in local before immediately returning it</LongDescription> Modified: trunk/fb-contrib/samples/NAB_Sample.java =================================================================== --- trunk/fb-contrib/samples/NAB_Sample.java 2007-01-09 07:49:30 UTC (rev 777) +++ trunk/fb-contrib/samples/NAB_Sample.java 2007-01-21 03:23:57 UTC (rev 778) @@ -40,4 +40,15 @@ Double d = new Double(0.0); Double dd = Double.valueOf(d); } + + public void testNeedsParse(String data) + { + boolean bo = Boolean.valueOf(data).booleanValue(); + byte b = Byte.valueOf(data).byteValue(); + short s = Short.valueOf(data).shortValue(); + int i = Integer.valueOf(data).intValue(); + long l = Long.valueOf(data).longValue(); + float f = Float.valueOf(data).floatValue(); + double d = Double.valueOf(data).doubleValue(); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-01-09 07:49:30 UTC (rev 777) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-01-21 03:23:57 UTC (rev 778) @@ -35,6 +35,7 @@ { private static final int SEEN_NOTHING = 0; private static final int SEEN_VALUE = 1; + private static final int SEEN_VALUEOF = 2; private static final Map<String, String[]> boxClasses = new HashMap<String, String[]>(); static { @@ -79,7 +80,15 @@ if (boxSigs[0].equals(methodName + methodSig)) { state = SEEN_VALUE; } + } + } else if (seen == INVOKESTATIC) { + boxClass = getClassConstantOperand(); + if (boxClasses.containsKey(boxClass)) { + if ("valueOf".equals(getNameConstantOperand()) && getSigConstantOperand().startsWith("(Ljava/lang/String;)")) { + state = SEEN_VALUEOF; + } + } } break; @@ -91,7 +100,7 @@ if ("<init>".equals(methodName)) { String methodSig = getSigConstantOperand(); if (boxSig.equals(methodSig)) { - bugReporter.reportBug(new BugInstance(this, "NAB_NEEDLESS_AUTOBOXING", NORMAL_PRIORITY) + bugReporter.reportBug(new BugInstance(this, "NAB_NEEDLESS_AUTOBOXING_CTOR", NORMAL_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(this)); @@ -105,7 +114,7 @@ if ("valueOf".equals(methodName)) { String methodSig = getSigConstantOperand(); if (boxSig.equals(methodSig)) { - bugReporter.reportBug(new BugInstance(this, "NAB_NEEDLESS_AUTOBOXING", NORMAL_PRIORITY) + bugReporter.reportBug(new BugInstance(this, "NAB_NEEDLESS_AUTOBOXING_VALUEOF", NORMAL_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(this)); @@ -115,6 +124,19 @@ } state = SEEN_NOTHING; break; - } + + case SEEN_VALUEOF: + if (seen == INVOKEVIRTUAL) { + String[] boxSigs = boxClasses.get(boxClass); + if (boxSigs[0].equals(getNameConstantOperand() + getSigConstantOperand())) { + bugReporter.reportBug(new BugInstance(this, "NAB_NEEDLESS_AUTOBOXING_PARSE", 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-01-27 06:09:10
|
Revision: 780 http://svn.sourceforge.net/fb-contrib/?rev=780&view=rev Author: dbrosius Date: 2007-01-26 22:09:09 -0800 (Fri, 26 Jan 2007) Log Message: ----------- Initial Checkin: USS Detector - not even close, yet. Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/USS_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-01-27 03:12:17 UTC (rev 779) +++ trunk/fb-contrib/etc/findbugs.xml 2007-01-27 06:09:09 UTC (rev 780) @@ -252,29 +252,29 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparatorReturnValues" speed="fast" - reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" - disabled="true" /> + reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" /> <Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri" speed="fast" - reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM" - disabled="true" /> + reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM" /> <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" - reports="BAS_BLOATED_ASSIGNMENT_SCOPE" - disabled="true" /> + reports="BAS_BLOATED_ASSIGNMENT_SCOPE" /> <Detector class="com.mebigfatguy.fbcontrib.detect.SpoiledChildInterfaceImplementor" speed="fast" - reports="SCI_SPOILED_CHILD_INTERFACE_IMPLEMENTOR" - disabled="true" /> + reports="SCI_SPOILED_CHILD_INTERFACE_IMPLEMENTOR" /> <Detector class="com.mebigfatguy.fbcontrib.detect.DeletingWhileIterating" speed="fast" - reports="DWI_DELETING_WHILE_ITERATING" - disabled="true" /> + reports="DWI_DELETING_WHILE_ITERATING" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.UseSplit" + speed="fast" + reports="USS_USE_STRING_SPLIT" /> + + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -354,4 +354,5 @@ <BugPattern abbrev="BAS" type="BAS_BLOATED_ASSIGNMENT_SCOPE" category="PERFORMANCE" experimental="true" /> <BugPattern abbrev="SCII" type="SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR" category="STYLE" experimental="true" /> <BugPattern abbrev="DWI" type="DWI_DELETING_WHILE_ITERATING" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="USS" type="USS_USE_STRING_SPLIT" 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-01-27 03:12:17 UTC (rev 779) +++ trunk/fb-contrib/etc/messages.xml 2007-01-27 06:09:09 UTC (rev 780) @@ -727,6 +727,16 @@ ]]> </Details> </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.UseSplit"> + <Details> + <![CDATA[ + <p>looks for code that builds an array by using a StringTokenizer to break up + a string and place individual elements into an array. It is simpler to use + String.split instead.</p> + ]]> + </Details> + </Detector> <!-- BugPattern --> @@ -1725,6 +1735,19 @@ </Details> </BugPattern> + <BugPattern type="USS_USE_STRING_SPLIT"> + <ShortDescription>Method builds String array using String Tokenizing</ShortDescription> + <LongDescription>Method {1} builds String array using String Tokenizing</LongDescription> + <Details> + <![CDATA[ + <p>This method uses a StringTokenizer to split up a String and then walks thru the + separated elements and builds an array from these enumerated values. It is simpler + and easier to use the String.split method. + </p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -1787,4 +1810,5 @@ <BugCode abbrev="BAS">Bloated Assignment Scope</BugCode> <BugCode abbrev="SCII">Spoiled Child Interface Implementor</BugCode> <BugCode abbrev="DWI">Deleting While Iterating</BugCode> + <BugCode abbrev="USS">Use String Split</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/USS_Sample.java =================================================================== --- trunk/fb-contrib/samples/USS_Sample.java (rev 0) +++ trunk/fb-contrib/samples/USS_Sample.java 2007-01-27 06:09:09 UTC (rev 780) @@ -0,0 +1,64 @@ +import java.util.StringTokenizer; + +public class USS_Sample +{ + public String[] testUss1(String s) + { + StringTokenizer st = new StringTokenizer(s, ";"); + int count = st.countTokens(); + String[] sarray = new String[count]; + + int i = 0; + while (st.hasMoreTokens()) + { + sarray[i] = st.nextToken(); + i++; + } + + return sarray; + } + + public String[] testUss2(String s) + { + StringTokenizer st = new StringTokenizer(s, ";"); + int count = st.countTokens(); + String[] sarray = new String[count]; + + int i = 0; + while (st.hasMoreTokens()) + { + sarray[i++] = st.nextToken(); + } + + return sarray; + } + + public String[] testUss3(String s) + { + StringTokenizer st = new StringTokenizer(s, ";"); + int count = st.countTokens(); + String[] sarray = new String[count]; + + for (int i = 0; i < count; i++) + { + sarray[i++] = st.nextToken(); + } + + return sarray; + } + + public String[] testUss4(String s) + { + StringTokenizer st = new StringTokenizer(s, ";"); + int count = st.countTokens(); + String[] sarray = new String[count]; + + int i = 0; + while (st.hasMoreElements()) + { + sarray[i++] = (String)st.nextElement(); + } + + return sarray; + } +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-01-27 06:09:09 UTC (rev 780) @@ -0,0 +1,132 @@ +/* + * fb-contrib - Auxilliary 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 java.util.HashMap; +import java.util.Map; + +import org.apache.bcel.classfile.Code; + +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; + +public class UseSplit extends BytecodeScanningDetector +{ + public static final int SEEN_NOTHING = 0; + public static final int SEEN_STRINGTOKENIZER = 1; + public static final int SEEN_COUNTTOKENS = 2; + public static final int SEEN_NEWARRAY = 3; + public static final int SEEN_HASMORE = 4; + public static final int SEEN_NEXT = 5; + public static final int SEEN_ARRAYSTORE = 6; + + + private BugReporter bugReporter; + private OpcodeStack stack; + private Map<Integer, Integer> regValueType; + private int state; + + public UseSplit(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + @Override + public void visitClassContext(ClassContext classContext) { + try { + stack = new OpcodeStack(); + regValueType = new HashMap<Integer, Integer>(); + super.visitClassContext(classContext); + } finally { + stack = null; + regValueType = null; + } + } + + /** + * implements the visitor to reset the stack + * + * @param obj the context object of the currently parsed code block + */ + @Override + public void visitCode(Code obj) { + stack.resetForMethodEntry(this); + regValueType.clear(); + state = SEEN_NOTHING; + super.visitCode(obj); + } + + @Override + public void sawOpcode(int seen) { + int stackState = SEEN_NOTHING; + try { + stack.mergeJumps(this); + + if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { + int reg = RegisterUtils.getALoadReg(this, seen); + Integer type = regValueType.get(Integer.valueOf(reg)); + if (type != null) + stackState = type.intValue(); + return; + } + + switch (state) { + case SEEN_NOTHING: + if (seen == INVOKESTATIC) { + if (("java/util/StringTokenizer".equals(getClassConstantOperand())) + && ("<init>".equals(getNameConstantOperand())) + && ("(Ljava/lang/String;Ljava/lang/String;)V".equals(getSigConstantOperand()))) { + state = SEEN_STRINGTOKENIZER; + stackState = state; + } + } + break; + + case SEEN_STRINGTOKENIZER: + if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { + int reg = RegisterUtils.getAStoreReg(this, seen); + regValueType.put(Integer.valueOf(reg), Integer.valueOf(SEEN_STRINGTOKENIZER)); + } + break; + + default: + if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { + int reg = RegisterUtils.getAStoreReg(this, seen); + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + regValueType.put(Integer.valueOf(reg), (Integer)item.getUserValue()); + } + } + break; + } + } finally { + stack.sawOpcode(this, seen); + if (stackState != SEEN_NOTHING) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + item.setUserValue(Integer.valueOf(stackState)); + } + } + } + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 09:17:10
|
Revision: 787 http://svn.sourceforge.net/fb-contrib/?rev=787&view=rev Author: dbrosius Date: 2007-01-28 01:17:10 -0800 (Sun, 28 Jan 2007) Log Message: ----------- document USS Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2007-01-28 09:14:29 UTC (rev 786) +++ trunk/fb-contrib/htdocs/index.html 2007-01-28 09:17:10 UTC (rev 787) @@ -66,7 +66,11 @@ Looks for deletion of items from a collection using the remove method of the collection at the same time that the collection is being iterated on. If this occurs the iterator will become invalid and throw a ConcurrentModificationException. - Instead, the remove should be called on the iterator itself.</li + Instead, the remove should be called on the iterator itself.</li> + <li><b>[USS] Use String Split</b><br/> + Looks for code that builds an array by using a StringTokenizer to break up + a string and place individual elements into an array. It is simpler to use + String.split instead.</li> </ul> </div> <hr/> Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-01-28 09:14:29 UTC (rev 786) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-01-28 09:17:10 UTC (rev 787) @@ -31,6 +31,12 @@ import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.ba.ClassContext; +/** + * looks for code that builds an array by using a StringTokenizer to break up + * a string and place individual elements into an array. It is simpler to use + * String.split instead. + + */ public class UseSplit extends BytecodeScanningDetector { public static final int SEEN_NOTHING = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 16:25:36
|
Revision: 789 http://svn.sourceforge.net/fb-contrib/?rev=789&view=rev Author: dbrosius Date: 2007-01-28 08:25:34 -0800 (Sun, 28 Jan 2007) Log Message: ----------- fix some false positives Modified Paths: -------------- trunk/fb-contrib/samples/USS_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java Modified: trunk/fb-contrib/samples/USS_Sample.java =================================================================== --- trunk/fb-contrib/samples/USS_Sample.java 2007-01-28 09:23:52 UTC (rev 788) +++ trunk/fb-contrib/samples/USS_Sample.java 2007-01-28 16:25:34 UTC (rev 789) @@ -61,4 +61,19 @@ return sarray; } + + public String[] testUssFP5(String s) + { + StringTokenizer st = new StringTokenizer(s, ";"); + int count = st.countTokens(); + String[] sarray = new String[count]; + + int i = 0; + while (st.hasMoreElements()) + { + sarray[i++] = "***" + (String)st.nextElement(); + } + + return sarray; + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-01-28 09:23:52 UTC (rev 788) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-01-28 16:25:34 UTC (rev 789) @@ -106,6 +106,8 @@ Integer type = regValueType.get(Integer.valueOf(reg)); if (type != null) state = type.intValue(); + else + state = SEEN_NOTHING; return; } if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { @@ -122,6 +124,8 @@ Integer type = regValueType.get(Integer.valueOf(reg)); if (type != null) state = type.intValue(); + else + state = SEEN_NOTHING; return; } if ((seen == ISTORE) || ((seen >= ISTORE_0) && (seen <= ISTORE_3))) { @@ -200,9 +204,12 @@ if (seen == AASTORE) { if ((pc > loopStart) && (pc < loopEnd)) { if (stack.getStackDepth() > 2) { - OpcodeStack.Item item = stack.getStackItem(2); - Integer type = (Integer)item.getUserValue(); - if ((type != null) && (type.intValue() == SEEN_NEWARRAY)) { + OpcodeStack.Item arrayItem = stack.getStackItem(2); + Integer arrayType = (Integer)arrayItem.getUserValue(); + OpcodeStack.Item elemItem = stack.getStackItem(0); + Integer elemType = (Integer)elemItem.getUserValue(); + if (((arrayType != null) && (arrayType.intValue() == SEEN_NEWARRAY)) + && ((elemType != null) && (elemType.intValue() == SEEN_NEXT))) { bugReporter.reportBug(new BugInstance(this, "USS_USE_STRING_SPLIT", NORMAL_PRIORITY) .addClass(this) .addMethod(this) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 21:47:44
|
Revision: 802 http://svn.sourceforge.net/fb-contrib/?rev=802&view=rev Author: dbrosius Date: 2007-01-28 13:47:38 -0800 (Sun, 28 Jan 2007) Log Message: ----------- remove a big false positive area where the implementation of a interface method declares that it DOES NOT throw an exception defined by the interface, and the method that uses this method doesn't handle that type of exception. Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/samples/OCP_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-01-28 21:08:03 UTC (rev 801) +++ trunk/fb-contrib/etc/findbugs.xml 2007-01-28 21:47:38 UTC (rev 802) @@ -41,7 +41,7 @@ reports="CC_CYCLOMATIC_COMPLEXITY" /> <Detector class="com.mebigfatguy.fbcontrib.detect.OverlyConcreteParameter" - speed="moderate" + speed="slow" reports="OCP_OVERLY_CONCRETE_PARAMETER" /> <Detector class="com.mebigfatguy.fbcontrib.detect.ListIndexedIterating" Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-01-28 21:08:03 UTC (rev 801) +++ trunk/fb-contrib/etc/messages.xml 2007-01-28 21:47:38 UTC (rev 802) @@ -66,7 +66,7 @@ <p> Looks for parameters that are defined by classes, but only use methods defined by an implemented interface or super class. Relying on concrete classes in public signatures causes cohesion, and makes low impact changes more difficult.</p> - <p>It is a moderately fast detector</p> + <p>It is a slow detector</p> ]]> </Details> </Detector> Modified: trunk/fb-contrib/samples/OCP_Sample.java =================================================================== --- trunk/fb-contrib/samples/OCP_Sample.java 2007-01-28 21:08:03 UTC (rev 801) +++ trunk/fb-contrib/samples/OCP_Sample.java 2007-01-28 21:47:38 UTC (rev 802) @@ -2,6 +2,7 @@ import java.awt.event.ActionListener; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashSet; import java.util.Iterator; @@ -51,6 +52,8 @@ public static interface A { public void test(); + + public void fp() throws IOException; } public static class B implements A @@ -61,10 +64,20 @@ { } + + public void fp() + { + + } } public void actionPerformed(ActionEvent ae) { } + + public void ocpFalseFPDueToExceptionSig(B b) + { + b.fp(); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 21:08:03 UTC (rev 801) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 21:47:38 UTC (rev 802) @@ -29,6 +29,7 @@ import org.apache.bcel.Constants; import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.CodeException; import org.apache.bcel.classfile.ExceptionTable; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.LocalVariable; @@ -37,6 +38,7 @@ import org.apache.bcel.generic.Type; import com.mebigfatguy.fbcontrib.utils.Integer14; +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; @@ -212,11 +214,8 @@ } } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { - int reg; - if (seen == ALOAD) - reg = this.getRegisterOperand(); - else - reg = seen - ALOAD_0; + int reg = RegisterUtils.getALoadReg(this, seen); + int parm = reg; if (!methodIsStatic) parm--; @@ -254,7 +253,7 @@ parm++; //users expect 1 based parameters String infName = definers.keySet().iterator().next().getClassName(); - bugReporter.reportBug( new BugInstance( this, "OCP_OVERLY_CONCRETE_PARAMETER", NORMAL_PRIORITY) + bugReporter.reportBug( new BugInstance(this, "OCP_OVERLY_CONCRETE_PARAMETER", NORMAL_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(this, 0) @@ -356,6 +355,15 @@ for (MethodInfo mi : methodSigs) { if (methodInfo.equals(mi)) { methodDefined = true; + String[] exceptions = mi.getMethodExceptions(); + if (exceptions != null) { + for (String ex : exceptions) { + if (!isExceptionHandled(ex)) { + methodDefined = false; + break; + } + } + } break; } } @@ -368,6 +376,48 @@ } } + /** + * returns whether this exception is handled either in a try/catch or throws clause at this pc + * + * @param ex the name of the exception + * + * @return whether the exception is handled + */ + private boolean isExceptionHandled(String ex) { + try { + JavaClass thrownEx = Repository.lookupClass(ex); + //First look at the throws clause + ExceptionTable et = getMethod().getExceptionTable(); + if (et != null) { + String[] throwClauseExNames = et.getExceptionNames(); + for (String throwClauseExName : throwClauseExNames) { + JavaClass throwClauseEx = Repository.lookupClass(throwClauseExName); + if (thrownEx.instanceOf(throwClauseEx)) + return true; + } + } + // Next look at the try catch blocks + CodeException[] catchExs = getCode().getExceptionTable(); + if (catchExs != null) { + int pc = getPC(); + for (CodeException catchEx : catchExs) { + if ((pc >= catchEx.getStartPC()) && (pc <= catchEx.getEndPC())) { + int type = catchEx.getCatchType(); + if (type != 0) { + String catchExName = getConstantPool().getConstantString(type, Constants.CONSTANT_Class); + JavaClass catchException = Repository.lookupClass(catchExName); + if (thrownEx.instanceOf(catchException)) + return true; + } + } + } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } + return false; + } + private void removeUselessDefiners(String parmSig, final int reg) { if (parmSig.startsWith("L")) { parmSig = parmSig.substring( 1, parmSig.length() - 1).replace('/', '.'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-30 06:47:16
|
Revision: 805 http://svn.sourceforge.net/fb-contrib/?rev=805&view=rev Author: dbrosius Date: 2007-01-29 22:47:15 -0800 (Mon, 29 Jan 2007) Log Message: ----------- remove some false positives because the state wasn't set back after state is SEEN_NEXT, and no appropriate action was taken Modified Paths: -------------- trunk/fb-contrib/samples/USS_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java Modified: trunk/fb-contrib/samples/USS_Sample.java =================================================================== --- trunk/fb-contrib/samples/USS_Sample.java 2007-01-30 06:12:31 UTC (rev 804) +++ trunk/fb-contrib/samples/USS_Sample.java 2007-01-30 06:47:15 UTC (rev 805) @@ -76,4 +76,25 @@ return sarray; } + + public String[] testUssFP6(String s) + { + StringTokenizer st = new StringTokenizer(s, ";"); + int count = st.countTokens(); + String[] sarray = new String[count]; + + int i = 0; + while (st.hasMoreTokens()) + { + String x = st.nextToken(); + if (x.equals("*")) + x = "Star"; + + sarray[i++] = x; + } + + return sarray; + } + + } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-01-30 06:12:31 UTC (rev 804) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-01-30 06:47:15 UTC (rev 805) @@ -217,12 +217,9 @@ } } } - } else if (seen == INVOKEVIRTUAL) { - String clsName = getClassConstantOperand(); - if ("java/lang/StringBuffer".equals(clsName) || "java/lang/StringBuilder".equals(clsName)) { - state = SEEN_NOTHING; - } } + state = SEEN_NOTHING; + break; } } 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...> - 2007-01-31 03:28:14
|
Revision: 807 http://svn.sourceforge.net/fb-contrib/?rev=807&view=rev Author: dbrosius Date: 2007-01-30 19:28:10 -0800 (Tue, 30 Jan 2007) Log Message: ----------- get ready for 3.2.0 Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2007-01-30 08:35:27 UTC (rev 806) +++ trunk/fb-contrib/build.xml 2007-01-31 03:28:10 UTC (rev 807) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.1.0"/> + <property name="fb-contrib.version" value="3.2.0"/> <target name="clean" description="removes all generated collateral"> <delete dir="${classes.dir}"/> Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-01-30 08:35:27 UTC (rev 806) +++ trunk/fb-contrib/etc/findbugs.xml 2007-01-31 03:28:10 UTC (rev 807) @@ -261,7 +261,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" reports="BAS_BLOATED_ASSIGNMENT_SCOPE" - disabled="true" /> + hidden="true" /> <Detector class="com.mebigfatguy.fbcontrib.detect.SpoiledChildInterfaceImplementor" speed="fast" Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2007-01-30 08:35:27 UTC (rev 806) +++ trunk/fb-contrib/htdocs/index.html 2007-01-31 03:28:10 UTC (rev 807) @@ -48,9 +48,9 @@ <a href="bugdescriptions.html">Bug Descriptions</a> <hr/> - <img id="svn_image" src="flip2.gif" onClick="toggleBlock('svn', 'svn_image');" align="top"/> - Detectors added in svn<br/> - <div id="svn" style="display:block;"> + <img id="v3_2_0_image" src="flip2.gif" onClick="toggleBlock('v3_2_0', 'v3_2_0_image');" align="top"/> + Detectors added in v3.2.0<br/> + <div id="v3_2_0" style="display:block;"> <ul> <li><b>[SCRV] Suspicious Comparator Return Values</b><br/> Looks for classes that implement Comparator or Comparable, and whose compare or compareTo This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-31 03:29:34
|
Revision: 808 http://svn.sourceforge.net/fb-contrib/?rev=808&view=rev Author: dbrosius Date: 2007-01-30 19:29:33 -0800 (Tue, 30 Jan 2007) Log Message: ----------- get ready for 3.2.0 Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/FBContrib.java Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2007-01-31 03:28:10 UTC (rev 807) +++ trunk/fb-contrib/build.xml 2007-01-31 03:29:33 UTC (rev 808) @@ -142,7 +142,7 @@ destdir="${javadoc.dir}" windowtitle="fb-contrib api"> <doctitle><![CDATA[<h1>fb-contrib javadoc</h1>]]></doctitle> - <bottom><![CDATA[<i>Copyright © 2005-2006 MeBigFatGuy.com. All Rights Reserved.</i>]]></bottom> + <bottom><![CDATA[<i>Copyright © 2005-2007 MeBigFatGuy.com. All Rights Reserved.</i>]]></bottom> </javadoc> </target> </project> \ No newline at end of file Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/FBContrib.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/FBContrib.java 2007-01-31 03:28:10 UTC (rev 807) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/FBContrib.java 2007-01-31 03:29:33 UTC (rev 808) @@ -28,7 +28,7 @@ * @param args standard command line args */ public static void main(final String[] args) { - JOptionPane.showMessageDialog( null, "To use fb-contrib, copy this jar file into your local FindBugs plugin directory, and use FindBugs as usual.\n\nfb-contrib is a trademark of MeBigFatGuy.com\nFindBugs is a trademark of the University of Maryland", "fb-contrib: copyright 2005-2006", JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showMessageDialog( null, "To use fb-contrib, copy this jar file into your local FindBugs plugin directory, and use FindBugs as usual.\n\nfb-contrib is a trademark of MeBigFatGuy.com\nFindBugs is a trademark of the University of Maryland", "fb-contrib: copyright 2005-2007", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-02-01 08:00:26
|
Revision: 811 http://svn.sourceforge.net/fb-contrib/?rev=811&view=rev Author: dbrosius Date: 2007-02-01 00:00:24 -0800 (Thu, 01 Feb 2007) Log Message: ----------- Initial checkin - SJVU .. not even close Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/SJVU_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-02-01 07:58:41 UTC (rev 810) +++ trunk/fb-contrib/etc/findbugs.xml 2007-02-01 08:00:24 UTC (rev 811) @@ -275,7 +275,13 @@ speed="fast" reports="USS_USE_STRING_SPLIT" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousJDKVersionUse" + speed="slow" + reports="SJVU_SUSPICIOUS_JDK_VERSION_USE" + hidden="true" + disabled="true" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -356,4 +362,5 @@ <BugPattern abbrev="SCII" type="SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR" category="STYLE" experimental="true" /> <BugPattern abbrev="DWI" type="DWI_DELETING_WHILE_ITERATING" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="USS" type="USS_USE_STRING_SPLIT" category="STYLE" experimental="true" /> + <BugPattern abbrev="SJVU" type="SJVU_SUSPICIOUS_JDK_VERSION_USE" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-02-01 07:58:41 UTC (rev 810) +++ trunk/fb-contrib/etc/messages.xml 2007-02-01 08:00:24 UTC (rev 811) @@ -737,6 +737,13 @@ ]]> </Details> </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousJDKVersionUse"> + <Details> + <![CDATA[ + ]]> + </Details> + </Detector> <!-- BugPattern --> @@ -1763,6 +1770,15 @@ </Details> </BugPattern> + <BugPattern type="SJVU_SUSPICIOUS_JDK_VERSION_USE"> + <ShortDescription></ShortDescription> + <LongDescription></LongDescription> + <Details> + <![CDATA[ + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -1826,4 +1842,5 @@ <BugCode abbrev="SCII">Spoiled Child Interface Implementor</BugCode> <BugCode abbrev="DWI">Deleting While Iterating</BugCode> <BugCode abbrev="USS">Use String Split</BugCode> + <BugCode abbrev="SJVU">Suspicious JDK VersionUse</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/SJVU_Sample.java =================================================================== --- trunk/fb-contrib/samples/SJVU_Sample.java (rev 0) +++ trunk/fb-contrib/samples/SJVU_Sample.java 2007-02-01 08:00:24 UTC (rev 811) @@ -0,0 +1,8 @@ + +public class SJVU_Sample +{ + public void test14using15(int i) + { + Integer ii = Integer.valueOf(i); + } +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2007-02-01 08:00:24 UTC (rev 811) @@ -0,0 +1,178 @@ +/* + * fb-contrib - Auxilliary 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 java.io.File; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.bcel.Constants; +import org.apache.bcel.classfile.JavaClass; + +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.ba.ClassContext; + +public class SuspiciousJDKVersionUse extends BytecodeScanningDetector +{ + private static final Map<Integer, String> verRegEx = new HashMap<Integer, String>(); + static { + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_1), "(jdk|jre)1.1"); + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_2), "(jdk|jre)1.2"); + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_3), "(jdk|jre)1.3"); + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_4), "(jdk|jre)1.4"); + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_5), "(jdk|jre)1.5"); + verRegEx.put(Integer14.valueOf(50), "jdk1.6"); + } + private static final Pattern jarPattern = Pattern.compile("jar:file:/*([^!]*)"); + + private Map<String, File> versionPaths; + private Map<Integer, Map<String, Set<String>>> validMethodsByVersion; + private File jdksRoot = null; + private URLClassLoader jdkLoader; + private Integer clsMajorVersion; + private BugReporter bugReporter; + + public SuspiciousJDKVersionUse(BugReporter bugReporter) { + this.bugReporter = bugReporter; + versionPaths = new HashMap<String, File>(); + validMethodsByVersion = new HashMap<Integer, Map<String, Set<String>>>(); + } + + @Override + public void visitClassContext(ClassContext classContext) { + try { + JavaClass cls = classContext.getJavaClass(); + clsMajorVersion = Integer14.valueOf(cls.getMajor()); + File rtJar = getRTJarFile(cls); + jdkLoader = new URLClassLoader(new URL[] {rtJar.toURL()}); + super.visitClassContext(classContext); + } catch (MalformedURLException mue) { + //Hmm, what to do + } finally { + jdkLoader = null; + } + } + + @Override + public void sawOpcode(int seen) { + + String clsName = null; + try { + if ((seen == INVOKEVIRTUAL) + || (seen == INVOKEINTERFACE) + || (seen == INVOKESTATIC) + || (seen == INVOKESPECIAL)) { + clsName = getClassConstantOperand(); + if ((clsName.startsWith("java/")) + || (clsName.startsWith("javax/"))) { + Map<String, Set<String>> validMethods = validMethodsByVersion.get(clsMajorVersion); + if (validMethods == null) { + validMethods = new HashMap<String, Set<String>>(); + validMethodsByVersion.put(clsMajorVersion, validMethods); + } + Set<String> methodInfos = validMethods.get(clsName); + if (methodInfos == null) { + Class c = jdkLoader.loadClass(clsName.replace('/', '.')); + Method[] methods = c.getDeclaredMethods(); + + methodInfos = new HashSet<String>(); + validMethods.put(clsName, methodInfos); + + for (Method m : methods) { + if ((m.getModifiers() & Modifier.PRIVATE) == 0) { + methodInfos.add(m.toString()); + } + } + } + } + } + } catch (ClassNotFoundException cnfe) { + if (clsName.startsWith("java/")) { + bugReporter.reportBug(new BugInstance(this, "SJVU_SUSPICIOUS_JDK_VERSION_USE", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + + private File getRTJarFile(JavaClass cls) { + String versionStr = verRegEx.get(clsMajorVersion); + if (versionStr == null) + return null; + + File rtPath = versionPaths.get(versionStr); + if (rtPath != null) + return rtPath; + + if (jdksRoot == null) { + URL jdkUrl = SuspiciousJDKVersionUse.class.getResource("/java/lang/Object.class"); + if (jdkUrl != null) { + Matcher m = jarPattern.matcher(jdkUrl.toExternalForm()); + + if (m.find()) { + String path = m.group(1); + jdksRoot = new File(path); + Pattern verPat = Pattern.compile(versionStr); + m = verPat.matcher(jdksRoot.getName()); + while ((jdksRoot.getParentFile() != null) && !m.find()) { + jdksRoot = jdksRoot.getParentFile(); + m = verPat.matcher(jdksRoot.getName()); + } + + if (jdksRoot.getParentFile() == null) + return null; + + jdksRoot = new File(URLDecoder.decode(jdksRoot.getParentFile().getPath())); + + File[] possibleJdks = jdksRoot.listFiles(); + for (File possibleJdk : possibleJdks) { + m = verPat.matcher(possibleJdk.getName()); + if (m.find()) { + File wantedRtJar = new File(possibleJdk, "lib/rt.jar"); + if (!wantedRtJar.exists()) { + wantedRtJar = new File(possibleJdk, "jre/lib/rt.jar"); + if (!wantedRtJar.exists()) + return null; + } + versionPaths.put(versionStr, wantedRtJar); + return wantedRtJar; + } + } + } + } + } + + return null; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-02-02 05:06:55
|
Revision: 817 http://svn.sourceforge.net/fb-contrib/?rev=817&view=rev Author: dbrosius Date: 2007-02-01 21:06:53 -0800 (Thu, 01 Feb 2007) Log Message: ----------- starting to work Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/samples/SJVU_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2007-02-01 09:38:22 UTC (rev 816) +++ trunk/fb-contrib/build.xml 2007-02-02 05:06:53 UTC (rev 817) @@ -81,6 +81,17 @@ <classpath refid="fb-contrib.classpath"/> <classpath refid="fb-contrib.samples.classpath"/> </javac> + <delete file="${samples.dir}/SJVU_Sample.class"/> + <javac srcdir="${samples.dir}" + destdir="${samples.dir}" + source="1.4" + target="1.4" + deprecation="${javac.deprecation}" + debug="${javac.debug}"> + <include name="SJVU_Sample.java"/> + <classpath refid="fb-contrib.classpath"/> + <classpath refid="fb-contrib.samples.classpath"/> + </javac> </target> <target name="jar" depends="compile" description="produces the fb-contrib jar file"> Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-02-01 09:38:22 UTC (rev 816) +++ trunk/fb-contrib/etc/findbugs.xml 2007-02-02 05:06:53 UTC (rev 817) @@ -277,9 +277,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousJDKVersionUse" speed="slow" - reports="SJVU_SUSPICIOUS_JDK_VERSION_USE" - hidden="true" - disabled="true" /> + reports="SJVU_SUSPICIOUS_JDK_VERSION_USE" /> <!-- BugPattern --> Modified: trunk/fb-contrib/samples/SJVU_Sample.java =================================================================== --- trunk/fb-contrib/samples/SJVU_Sample.java 2007-02-01 09:38:22 UTC (rev 816) +++ trunk/fb-contrib/samples/SJVU_Sample.java 2007-02-02 05:06:53 UTC (rev 817) @@ -4,5 +4,9 @@ public void test14using15(int i) { Integer ii = Integer.valueOf(i); + StringBuilder sb = new StringBuilder(); + sb.append(ii.intValue()); } + + } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2007-02-01 09:38:22 UTC (rev 816) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2007-02-02 05:06:53 UTC (rev 817) @@ -18,12 +18,12 @@ */ package com.mebigfatguy.fbcontrib.detect; +import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; +import java.io.UnsupportedEncodingException; import java.net.URL; -import java.net.URLClassLoader; import java.net.URLDecoder; import java.util.HashMap; import java.util.HashSet; @@ -31,6 +31,8 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import org.apache.bcel.Constants; import org.apache.bcel.classfile.ClassParser; @@ -61,8 +63,8 @@ private Map<Integer, Map<String, Set<String>>> validMethodsByVersion; private Map<String, String> superNames; private File jdksRoot = null; - JavaClass cls; - private URLClassLoader jdkLoader; + private ZipFile jdkZip; + private JavaClass cls; private Integer clsMajorVersion; private BugReporter bugReporter; @@ -80,14 +82,20 @@ clsMajorVersion = Integer14.valueOf(cls.getMajor()); File rtJar = getRTJarFile(cls); if (rtJar != null) { - jdkLoader = new URLClassLoader(new URL[] {rtJar.toURL()}); + jdkZip = new ZipFile(rtJar); super.visitClassContext(classContext); } - } catch (MalformedURLException mue) { - //Hmm, what to do + } catch (Exception ze) { + // Hmm what to do? } finally { cls = null; - jdkLoader = null; + clsMajorVersion = null; + try { + if (jdkZip != null) + jdkZip.close(); + } catch (IOException ioe) { + } + jdkZip = null; } } @@ -98,8 +106,7 @@ InputStream is = null; try { - if ((seen == INVOKEVIRTUAL) - || (seen == INVOKEINTERFACE) + if ((seen == INVOKEVIRTUAL) //Interfaces are more difficult, ignore for now || (seen == INVOKESTATIC) || (seen == INVOKESPECIAL)) { clsName = getClassConstantOperand(); @@ -115,7 +122,8 @@ bugReporter.reportBug(new BugInstance(this, "SJVU_SUSPICIOUS_JDK_VERSION_USE", HIGH_PRIORITY) .addClass(this) .addMethod(this) - .addSourceLine(this)); + .addSourceLine(this) + .addCalledMethod(this)); } } } @@ -137,27 +145,35 @@ try { Set<String> methodInfos = validMethods.get(clsName); if (methodInfos == null) { - is = jdkLoader.getResourceAsStream(clsName + ".class"); - if (is != null) { - ClassParser parser = new ClassParser(is, clsName); - JavaClass calledClass = parser.parse(); - - superNames.put(clsName, calledClass.getSuperclassName().replace('.', '/')); - Method[] methods = calledClass.getMethods(); - - methodInfos = new HashSet<String>(); - validMethods.put(clsName, methodInfos); - - for (Method m : methods) { - if (!m.isPrivate()) + + ZipEntry ze = jdkZip.getEntry(clsName + ".class"); + if (ze != null) { + is = new BufferedInputStream(jdkZip.getInputStream(ze)); + if (is != null) { + ClassParser parser = new ClassParser(is, clsName); + JavaClass calledClass = parser.parse(); + + superNames.put(clsName, calledClass.getSuperclassName().replace('.', '/')); + Method[] methods = calledClass.getMethods(); + + methodInfos = new HashSet<String>(); + validMethods.put(clsName, methodInfos); + + for (Method m : methods) { methodInfos.add(m.getName() + m.getSignature()); + } + } - + else { + return true; + } + } else if (clsName.startsWith("java/")) { + bugReporter.reportBug(new BugInstance(this, "SJVU_SUSPICIOUS_JDK_VERSION_USE", HIGH_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this) + .addClass(clsName)); } - else { - return true; - } - } String wantedMethod = getNameConstantOperand() + getSigConstantOperand(); @@ -178,7 +194,7 @@ } } - private File getRTJarFile(JavaClass cls) { + private File getRTJarFile(JavaClass cls){ String versionStr = verRegEx.get(clsMajorVersion); if (versionStr == null) return null; @@ -205,7 +221,12 @@ if (jdksRoot.getParentFile() == null) return null; - jdksRoot = new File(URLDecoder.decode(jdksRoot.getParentFile().getPath())); + try { + String encoding = System.getProperty("file.encoding"); + jdksRoot = new File(URLDecoder.decode(jdksRoot.getParentFile().getPath(), encoding)); + } catch (UnsupportedEncodingException uee) { + return null; + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-02-04 03:19:08
|
Revision: 833 http://svn.sourceforge.net/fb-contrib/?rev=833&view=rev Author: dbrosius Date: 2007-02-03 19:19:07 -0800 (Sat, 03 Feb 2007) Log Message: ----------- add check for pattern Boxed.valueOf(Boxed.parseBoxed("1")) Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-02-04 02:45:07 UTC (rev 832) +++ trunk/fb-contrib/etc/findbugs.xml 2007-02-04 03:19:07 UTC (rev 833) @@ -115,7 +115,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessAutoboxing" speed="fast" - reports="NAB_NEEDLESS_AUTOBOXING_CTOR,NAB_NEEDLESS_AUTOBOXING_VALUEOF,NAB_NEEDLESS_AUTOBOXING_PARSE" /> + reports="NAB_NEEDLESS_AUTOBOXING_CTOR,NAB_NEEDLESS_AUTOBOXING_VALUEOF,NAB_NEEDLESS_BOXING_PARSE,NAB_NEEDLESS_BOXING_VALUEOF" /> <Detector class="com.mebigfatguy.fbcontrib.detect.UnnecessaryStoreBeforeReturn" speed="fast" @@ -306,7 +306,8 @@ <BugPattern abbrev="STS" type="STS_SPURIOUS_THREAD_STATES" category="MT_CORRECTNESS" /> <BugPattern abbrev="NAB" type="NAB_NEEDLESS_AUTOBOXING_CTOR" category="PERFORMANCE" /> <BugPattern abbrev="NAB" type="NAB_NEEDLESS_AUTOBOXING_VALUEOF" category="PERFORMANCE" /> - <BugPattern abbrev="NAB" type="NAB_NEEDLESS_AUTOBOXING_PARSE" category="PERFORMANCE" /> + <BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOXING_PARSE" category="PERFORMANCE" /> + <BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOXING_VALUEOF" 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-02-04 02:45:07 UTC (rev 832) +++ trunk/fb-contrib/etc/messages.xml 2007-02-04 03:19:07 UTC (rev 833) @@ -1057,9 +1057,9 @@ </Details> </BugPattern> - <BugPattern type="NAB_NEEDLESS_AUTOBOXING_PARSE"> - <ShortDescription>method converts String to primitive using excessive autoboxing</ShortDescription> - <LongDescription>method {1} converts String to primitive using excessive autoboxing</LongDescription> + <BugPattern type="NAB_NEEDLESS_BOXING_PARSE"> + <ShortDescription>method converts String to primitive using excessive boxing</ShortDescription> + <LongDescription>method {1} converts String to primitive using excessive boxing</LongDescription> <Details> <![CDATA[ <p>This method passes a String to a wrapped primitive object's valueOf method, which in turn calls @@ -1070,6 +1070,19 @@ </Details> </BugPattern> + <BugPattern type="NAB_NEEDLESS_BOXING_VALUEOF"> + <ShortDescription>method converts String to boxed primitive using excessive boxing</ShortDescription> + <LongDescription>method {1} converts String to boxed primitive using excessive boxing</LongDescription> + <Details> + <![CDATA[ + <p>This method passes a String to a wrapped primitive object's parse method, which in turn calls + the valueOf() method to convert to a boxed primitive. When it is desired to convert from a String + to a boxed primitive object, it is simpler to use the BoxedPrimitive.valueOf(myString) + method. </p> + ]]> + </Details> + </BugPattern> + <BugPattern type="USBR_UNNECESSARY_STORE_BEFORE_RETURN"> <ShortDescription>method stores return result in local before immediately returning it</ShortDescription> <LongDescription>method {1} stores return result in local before immediately returning it</LongDescription> Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-02-04 02:45:07 UTC (rev 832) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-02-04 03:19:07 UTC (rev 833) @@ -36,19 +36,31 @@ private static final int SEEN_NOTHING = 0; private static final int SEEN_VALUE = 1; private static final int SEEN_VALUEOF = 2; + private static final int SEEN_PARSE = 3; private static final Map<String, String[]> boxClasses = new HashMap<String, String[]>(); static { boxClasses.put("java/lang/Boolean", new String[] { "booleanValue()Z", "(Z)V", "(Z)Ljava/lang/Boolean;" }); boxClasses.put("java/lang/Character", new String[] { "charValue()C", "(C)V", "(C)Ljava/lang/Character;" }); boxClasses.put("java/lang/Byte", new String[] { "byteValue()B", "(B)V", "(B)Ljava/lang/Byte;" }); - boxClasses.put("java.lang/Short", new String[] { "shortValue()S", "(S)V", "(S)Ljava/lang/Short;" }); + boxClasses.put("java/lang/Short", new String[] { "shortValue()S", "(S)V", "(S)Ljava/lang/Short;" }); boxClasses.put("java/lang/Integer", new String[] { "intValue()I", "(I)V", "(I)Ljava/lang/Integer;" }); boxClasses.put("java/lang/Long", new String[] { "longValue()J", "(J)V", "(J)Ljava/lang/Long;" }); boxClasses.put("java/lang/Float", new String[] { "floatValue()F", "(F)V", "(F)Ljava/lang/Float;" }); boxClasses.put("java/lang/Double", new String[] { "doubleValue()D", "(D)V", "(D)Ljava/lang/Double;" }); } + private static final Map<String, String> parseClasses = new HashMap<String, String>(); + static { + parseClasses.put("java/lang/Boolean", "parseBoolean(Ljava/lang/String;)Z"); + parseClasses.put("java/lang/Byte", "parseByte(Ljava/lang/String;)B"); + parseClasses.put("java/lang/Short", "parseShort(Ljava/lang/String;)S"); + parseClasses.put("java/lang/Integer", "parseInt(Ljava/lang/String;)I"); + parseClasses.put("java/lang/Long", "parseLong(Ljava/lang/String;)J"); + parseClasses.put("java/lang/Float", "parseFloat(Ljava/lang/String;)F"); + parseClasses.put("java/lang/Double", "parseDouble(Ljava/lang/String;)D"); + } + private BugReporter bugReporter; private int state; private String boxClass; @@ -75,12 +87,10 @@ boxClass = getClassConstantOperand(); String[] boxSigs = boxClasses.get(boxClass); if (boxSigs != null) { - String methodName = getNameConstantOperand(); - String methodSig = getSigConstantOperand(); - if (boxSigs[0].equals(methodName + methodSig)) { + String methodInfo = getNameConstantOperand() + getSigConstantOperand(); + if (boxSigs[0].equals(methodInfo)) { state = SEEN_VALUE; } - } } else if (seen == INVOKESTATIC) { boxClass = getClassConstantOperand(); @@ -88,6 +98,15 @@ if ("valueOf".equals(getNameConstantOperand()) && getSigConstantOperand().startsWith("(Ljava/lang/String;)")) { state = SEEN_VALUEOF; } + else { + String parseSig = parseClasses.get(boxClass); + if (parseSig != null) { + String methodInfo = getNameConstantOperand() + getSigConstantOperand(); + if (parseSig.equals(methodInfo)) { + state = SEEN_PARSE; + } + } + } } } break; @@ -129,7 +148,7 @@ if (seen == INVOKEVIRTUAL) { String[] boxSigs = boxClasses.get(boxClass); if (boxSigs[0].equals(getNameConstantOperand() + getSigConstantOperand())) { - bugReporter.reportBug(new BugInstance(this, "NAB_NEEDLESS_AUTOBOXING_PARSE", NORMAL_PRIORITY) + bugReporter.reportBug(new BugInstance(this, "NAB_NEEDLESS_BOXING_PARSE", NORMAL_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(this)); @@ -137,6 +156,21 @@ } state = SEEN_NOTHING; break; + + case SEEN_PARSE: + if (seen == INVOKESTATIC) { + if (boxClass.equals(getClassConstantOperand())) { + if ("valueOf".equals(getNameConstantOperand())) { + bugReporter.reportBug(new BugInstance(this, "NAB_NEEDLESS_BOXING_VALUEOF", 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-02-04 03:29:45
|
Revision: 835 http://svn.sourceforge.net/fb-contrib/?rev=835&view=rev Author: dbrosius Date: 2007-02-03 19:29:45 -0800 (Sat, 03 Feb 2007) Log Message: ----------- add check for pattern new BoxedPrimitive(BoxedPrimitive.parseBoxedPrimitive("1")) Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-02-04 03:20:48 UTC (rev 834) +++ trunk/fb-contrib/etc/findbugs.xml 2007-02-04 03:29:45 UTC (rev 835) @@ -115,7 +115,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessAutoboxing" speed="fast" - reports="NAB_NEEDLESS_AUTOBOXING_CTOR,NAB_NEEDLESS_AUTOBOXING_VALUEOF,NAB_NEEDLESS_BOXING_PARSE,NAB_NEEDLESS_BOXING_VALUEOF" /> + reports="NAB_NEEDLESS_AUTOBOXING_CTOR,NAB_NEEDLESS_BOXING_STRING_CTOR,NAB_NEEDLESS_AUTOBOXING_VALUEOF,NAB_NEEDLESS_BOXING_PARSE,NAB_NEEDLESS_BOXING_VALUEOF" /> <Detector class="com.mebigfatguy.fbcontrib.detect.UnnecessaryStoreBeforeReturn" speed="fast" @@ -305,6 +305,7 @@ <BugPattern abbrev="SMII" type="SMII_STATIC_METHOD_INSTANCE_INVOCATION" category="STYLE" /> <BugPattern abbrev="STS" type="STS_SPURIOUS_THREAD_STATES" category="MT_CORRECTNESS" /> <BugPattern abbrev="NAB" type="NAB_NEEDLESS_AUTOBOXING_CTOR" category="PERFORMANCE" /> + <BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOXING_STRING_CTOR" category="PERFORMANCE" /> <BugPattern abbrev="NAB" type="NAB_NEEDLESS_AUTOBOXING_VALUEOF" category="PERFORMANCE" /> <BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOXING_PARSE" category="PERFORMANCE" /> <BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOXING_VALUEOF" category="PERFORMANCE" /> Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-02-04 03:20:48 UTC (rev 834) +++ trunk/fb-contrib/etc/messages.xml 2007-02-04 03:29:45 UTC (rev 835) @@ -1043,6 +1043,18 @@ ]]> </Details> </BugPattern> + + <BugPattern type="NAB_NEEDLESS_BOXING_STRING_CTOR"> + <ShortDescription>method passes parsed string to primitive wrapper constructor</ShortDescription> + <LongDescription>method {1} passes parsed string to primitive wrapper constructor</LongDescription> + <Details> + <![CDATA[ + <p>This method passes a primitive value retrieved from a BoxedPrimitive.parseBoxedPrimitive("1") call to + the same class's constructor. It is simpler to just pass the string to the BoxedPrimitives constructor. + </p> + ]]> + </Details> + </BugPattern> <BugPattern type="NAB_NEEDLESS_AUTOBOXING_VALUEOF"> <ShortDescription>method passes primitive wrapper to Wrapper class valueOf method</ShortDescription> Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-02-04 03:20:48 UTC (rev 834) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-02-04 03:29:45 UTC (rev 835) @@ -167,6 +167,13 @@ .addSourceLine(this)); } } + } else if (seen == INVOKESPECIAL) { + if ("<init>".equals(getNameConstantOperand()) && (boxClass.equals(getClassConstantOperand()))) { + bugReporter.reportBug(new BugInstance(this, "NAB_NEEDLESS_BOXING_STRING_CTOR", 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-02-05 13:27:19
|
Revision: 838 http://svn.sourceforge.net/fb-contrib/?rev=838&view=rev Author: dbrosius Date: 2007-02-05 05:27:13 -0800 (Mon, 05 Feb 2007) Log Message: ----------- get ready for 3.2.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-02-04 07:45:50 UTC (rev 837) +++ trunk/fb-contrib/build.xml 2007-02-05 13:27:13 UTC (rev 838) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.2.1"/> + <property name="fb-contrib.version" value="3.2.2"/> <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-02-04 07:45:50 UTC (rev 837) +++ trunk/fb-contrib/etc/findbugs.xml 2007-02-05 13:27:13 UTC (rev 838) @@ -277,7 +277,9 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousJDKVersionUse" speed="slow" - reports="SJVU_SUSPICIOUS_JDK_VERSION_USE" /> + reports="SJVU_SUSPICIOUS_JDK_VERSION_USE" + hidden="true" + disabled="true" /> <!-- BugPattern --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-02-06 03:50:33
|
Revision: 840 http://svn.sourceforge.net/fb-contrib/?rev=840&view=rev Author: dbrosius Date: 2007-02-05 19:50:33 -0800 (Mon, 05 Feb 2007) Log Message: ----------- add DWI_MODIFYING_WHILE_ITERATING bug pattern to DWI Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/samples/DWI_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-02-05 13:36:18 UTC (rev 839) +++ trunk/fb-contrib/etc/findbugs.xml 2007-02-06 03:50:33 UTC (rev 840) @@ -269,7 +269,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.DeletingWhileIterating" speed="fast" - reports="DWI_DELETING_WHILE_ITERATING" /> + reports="DWI_DELETING_WHILE_ITERATING,DWI_MODIFYING_WHILE_ITERATING" /> <Detector class="com.mebigfatguy.fbcontrib.detect.UseSplit" speed="fast" @@ -350,19 +350,20 @@ <BugPattern abbrev="URV" type="URV_CHANGE_RETURN_TYPE" category="STYLE" /> <BugPattern abbrev="URV" type="URV_INHERITED_METHOD_WITH_RELATED_TYPES" category="STYLE" /> <BugPattern abbrev="PIS" type="PIS_POSSIBLE_INCOMPLETE_SERIALIZATION" category="CORRECTNESS" /> - <BugPattern abbrev="SCRV" type="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="SPP" type="SPP_NEGATIVE_BITSET_ITEM" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="SPP" type="SPP_INTERN_ON_CONSTANT" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="SPP" type="SPP_NO_CHAR_SB_CTOR" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="SPP" type="SPP_USE_MATH_CONSTANT" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="SPP" type="SPP_STUTTERED_ASSIGNMENT" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="SPP" type="SPP_USE_ISNAN" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="SPP" type="SPP_USE_BIGDECIMAL_STRING_CTOR" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="SPP" type="SPP_STRINGBUFFER_WITH_EMPTY_STRING" category="PERFORMANCE" experimental="true" /> - <BugPattern abbrev="SPP" type="SPP_EQUALS_ON_ENUM" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="BAS" type="BAS_BLOATED_ASSIGNMENT_SCOPE" category="PERFORMANCE" experimental="true" /> - <BugPattern abbrev="SCII" type="SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR" category="STYLE" experimental="true" /> - <BugPattern abbrev="DWI" type="DWI_DELETING_WHILE_ITERATING" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="USS" type="USS_USE_STRING_SPLIT" category="STYLE" experimental="true" /> + <BugPattern abbrev="SCRV" type="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" category="CORRECTNESS" /> + <BugPattern abbrev="SPP" type="SPP_NEGATIVE_BITSET_ITEM" category="CORRECTNESS" /> + <BugPattern abbrev="SPP" type="SPP_INTERN_ON_CONSTANT" category="CORRECTNESS" /> + <BugPattern abbrev="SPP" type="SPP_NO_CHAR_SB_CTOR" category="CORRECTNESS" /> + <BugPattern abbrev="SPP" type="SPP_USE_MATH_CONSTANT" category="CORRECTNESS" /> + <BugPattern abbrev="SPP" type="SPP_STUTTERED_ASSIGNMENT" category="CORRECTNESS" /> + <BugPattern abbrev="SPP" type="SPP_USE_ISNAN" category="CORRECTNESS" /> + <BugPattern abbrev="SPP" type="SPP_USE_BIGDECIMAL_STRING_CTOR" category="CORRECTNESS" /> + <BugPattern abbrev="SPP" type="SPP_STRINGBUFFER_WITH_EMPTY_STRING" category="PERFORMANCE" /> + <BugPattern abbrev="SPP" type="SPP_EQUALS_ON_ENUM" 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" /> + <BugPattern abbrev="DWI" type="DWI_MODIFYING_WHILE_ITERATING" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="USS" type="USS_USE_STRING_SPLIT" category="STYLE" /> <BugPattern abbrev="SJVU" type="SJVU_SUSPICIOUS_JDK_VERSION_USE" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-02-05 13:36:18 UTC (rev 839) +++ trunk/fb-contrib/etc/messages.xml 2007-02-06 03:50:33 UTC (rev 840) @@ -1778,13 +1778,26 @@ <![CDATA[ <p>This method removes items from a collection using the remove method of the collection, while at the same time iterating across the collection. Doing this will invalidate the iterator, and further - user of it, will cause ConcurrentModificationExceptions to be thrown. To avoid this, the remove + use of it, will cause ConcurrentModificationExceptions to be thrown. To avoid this, the remove method of the iterator should be used. </p> ]]> </Details> </BugPattern> + <BugPattern type="DWI_MODIFYING_WHILE_ITERATING"> + <ShortDescription>Method modifies collection element while iterating</ShortDescription> + <LongDescription>Method {1} modifies collection element while iterating</LongDescription> + <Details> + <![CDATA[ + <p>This method modifies the contents of a collection using the collection api methods, while + at the same time iterating across the collection. Doing this will invalidate the iterator, and further + use of it, will cause ConcurrentModificationExceptions to be thrown. + </p> + ]]> + </Details> + </BugPattern> + <BugPattern type="USS_USE_STRING_SPLIT"> <ShortDescription>Method builds String array using String Tokenizing</ShortDescription> <LongDescription>Method {1} builds String array using String Tokenizing</LongDescription> Modified: trunk/fb-contrib/samples/DWI_Sample.java =================================================================== --- trunk/fb-contrib/samples/DWI_Sample.java 2007-02-05 13:36:18 UTC (rev 839) +++ trunk/fb-contrib/samples/DWI_Sample.java 2007-02-06 03:50:33 UTC (rev 840) @@ -1,3 +1,4 @@ +import java.util.Collection; import java.util.Iterator; import java.util.Set; @@ -13,4 +14,12 @@ bagOInts.remove(i); } } + + public void addIf(Set<String> s, Collection<String> c) { + for (String ss : s) + { + if (ss.equals("addem")) + s.addAll(c); + } + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-02-05 13:36:18 UTC (rev 839) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-02-06 03:50:33 UTC (rev 840) @@ -64,6 +64,18 @@ collectionMethods.add("keySet()Ljava/lang/Set;"); collectionMethods.add("values()Ljava/lang/Collection;"); } + private static final Set<String> modifyingMethods = new HashSet<String>(); + static { + modifyingMethods.add("add(Ljava/lang/Object;)Z"); + modifyingMethods.add("addAll(Ljava/util/Collection;)Z"); + modifyingMethods.add("addAll(ILjava/util/Collection;)Z"); + modifyingMethods.add("clear()V"); + modifyingMethods.add("remove(I)Ljava/lang/Object;"); + modifyingMethods.add("removeAll(Ljava/util/Collection;)Z"); + modifyingMethods.add("retainAll(Ljava/util/Collection;)Z"); + modifyingMethods.add("set(ILjava/lang/Object;)Ljava/lang/Object;"); + + } private BugReporter bugReporter; private OpcodeStack stack; @@ -164,6 +176,24 @@ } } } + } else if (modifyingMethods.contains(methodInfo)) { + if (stack.getStackDepth() > 1) { + OpcodeStack.Item itm = stack.getStackItem(1); + int id = findCollectionGroup(itm, true); + if (id >= 0) { + Integer it = groupToIterator.get(Integer14.valueOf(id)); + Loop loop = loops.get(it); + if (loop != null) { + int pc = getPC(); + if (loop.hasPC(pc)) { + bugReporter.reportBug(new BugInstance(this, "DWI_MODIFYING_WHILE_ITERATING", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + } } } else if ("java/util/Iterator".equals(className) && "hasNext()Z".equals(methodInfo)) { if (stack.getStackDepth() > 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |