fb-contrib-commit Mailing List for fb-contrib (Page 45)
Brought to you by:
dbrosius
You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(56) |
Oct
(60) |
Nov
(58) |
Dec
(89) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(66) |
Feb
(55) |
Mar
(85) |
Apr
(115) |
May
(35) |
Jun
(28) |
Jul
(3) |
Aug
(48) |
Sep
(37) |
Oct
(22) |
Nov
(14) |
Dec
(66) |
2007 |
Jan
(45) |
Feb
(63) |
Mar
(10) |
Apr
(1) |
May
(1) |
Jun
(12) |
Jul
|
Aug
|
Sep
(25) |
Oct
(21) |
Nov
(39) |
Dec
|
2008 |
Jan
(7) |
Feb
|
Mar
(26) |
Apr
(5) |
May
(2) |
Jun
(32) |
Jul
(9) |
Aug
(10) |
Sep
|
Oct
(3) |
Nov
(1) |
Dec
|
2009 |
Jan
(10) |
Feb
(31) |
Mar
(32) |
Apr
(35) |
May
(25) |
Jun
|
Jul
(31) |
Aug
(10) |
Sep
(95) |
Oct
(35) |
Nov
(10) |
Dec
(34) |
2010 |
Jan
(90) |
Feb
(4) |
Mar
(7) |
Apr
(20) |
May
(20) |
Jun
(13) |
Jul
(7) |
Aug
(18) |
Sep
(25) |
Oct
(4) |
Nov
(16) |
Dec
(2) |
2011 |
Jan
(1) |
Feb
|
Mar
(11) |
Apr
(3) |
May
(2) |
Jun
(26) |
Jul
(10) |
Aug
(2) |
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(1) |
2012 |
Jan
(3) |
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(14) |
Nov
(3) |
Dec
(4) |
2013 |
Jan
(3) |
Feb
(2) |
Mar
(1) |
Apr
(4) |
May
|
Jun
(1) |
Jul
(3) |
Aug
|
Sep
|
Oct
(4) |
Nov
(3) |
Dec
(3) |
2014 |
Jan
(4) |
Feb
(2) |
Mar
(4) |
Apr
(1) |
May
(2) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(4) |
Jun
|
Jul
|
Aug
(3) |
Sep
|
Oct
|
Nov
(3) |
Dec
(3) |
2016 |
Jan
(2) |
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
(1) |
Aug
(2) |
Sep
(4) |
Oct
(2) |
Nov
(7) |
Dec
|
2017 |
Jan
(1) |
Feb
|
Mar
(4) |
Apr
(5) |
May
(2) |
Jun
|
Jul
(2) |
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
(3) |
2018 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
(5) |
Jun
(2) |
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <dbr...@us...> - 2006-12-19 08:26:02
|
Revision: 741 http://svn.sourceforge.net/fb-contrib/?rev=741&view=rev Author: dbrosius Date: 2006-12-19 00:25:31 -0800 (Tue, 19 Dec 2006) Log Message: ----------- add fud warnings for BAS Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-12-19 08:19:21 UTC (rev 740) +++ trunk/fb-contrib/etc/messages.xml 2006-12-19 08:25:31 UTC (rev 741) @@ -697,7 +697,8 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope"> <Details> <![CDATA[ - <p>looks for assignments to variables in a scope larger than it's use. As long as the evaluation of the assignment + <p><b>THIS DETECTOR IS HIGHLY EXPERIMENTAL AND IS LIKELY TO CREATE A LOT OF FUD</b> + Looks for assignments to variables in a scope larger than it's use. As long as the evaluation of the assignment does not have side effects, the assignment can be moved into the inner scope where it is used.</p> ]]> </Details> @@ -1644,7 +1645,8 @@ <LongDescription>Method {1} assigns a variable in a larger scope then is needed</LongDescription> <Details> <![CDATA[ - <p>This method assigns a value to a variable in an outer scope compared to where the variable is actually used. + <p><b>THIS DETECTOR IS HIGHLY EXPERIMENTAL AND IS LIKELY TO CREATE A LOT OF FUD</b> + 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. Care should be taken however that the right hand side of the assignment does not contain side 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-19 08:16:34
|
Revision: 739 http://svn.sourceforge.net/fb-contrib/?rev=739&view=rev Author: dbrosius Date: 2006-12-19 00:16:30 -0800 (Tue, 19 Dec 2006) Log Message: ----------- starting to work Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-19 07:41:37 UTC (rev 738) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-19 08:16:30 UTC (rev 739) @@ -138,8 +138,8 @@ groupId = findCollectionGroup(itm, true); } } else if ("remove(Ljava/lang/Object;)Z".equals(methodInfo)) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item itm = stack.getStackItem(0); + if (stack.getStackDepth() > 1) { + OpcodeStack.Item itm = stack.getStackItem(1); int id = findCollectionGroup(itm, true); if (id >= 0) { Integer it = groupToIterator.get(id); @@ -196,8 +196,13 @@ if (id != null) { int target = getBranchTarget(); int gotoAddr = target - 3; - if (getCode().getCode()[gotoAddr] == GOTO) { - loops.put(id, new Loop(getPC(), gotoAddr)); + int ins = getCode().getCode()[gotoAddr]; + if (ins < 0) + ins = 256 + ins; + if (ins == GOTO) { + Integer reg = groupToIterator.get(id); + if (reg != null) + loops.put(reg, new Loop(getPC(), gotoAddr)); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-19 07:41:38
|
Revision: 738 http://svn.sourceforge.net/fb-contrib/?rev=738&view=rev Author: dbrosius Date: 2006-12-18 23:41:37 -0800 (Mon, 18 Dec 2006) Log Message: ----------- more fleshing out Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-19 06:57:27 UTC (rev 737) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-19 07:41:37 UTC (rev 738) @@ -32,6 +32,7 @@ import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; +import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.OpcodeStack; @@ -61,7 +62,8 @@ private BugReporter bugReporter; private OpcodeStack stack; private List<Set<Comparable>> collectionGroups; - private Map<Integer, Integer> iteratorToGroup; + private Map<Integer, Integer> groupToIterator; + private Map<Integer, Loop> loops; /** * constructs a DWI detector given the reporter to report bugs on @@ -72,7 +74,7 @@ } /** - * implements the visitor to setup the opcode stack, and collectionGroups + * implements the visitor to setup the opcode stack, collectionGroups, groupToIterator and loops * * @param classContext the context object of the currently parsed class */ @@ -83,24 +85,27 @@ try { stack = new OpcodeStack(); collectionGroups = new ArrayList<Set<Comparable>>(); - iteratorToGroup = new HashMap<Integer, Integer>(); + groupToIterator = new HashMap<Integer, Integer>(); + loops = new HashMap<Integer, Loop>(); super.visitClassContext(classContext); } finally { stack = null; collectionGroups = null; - iteratorToGroup = null; + groupToIterator = null; + loops = null; } } /** - * implements the visitor to reset the stack and collectionGroups + * implements the visitor to reset the stack, collectionGroups, groupToIterator and loops * * @param obj the context object of the currently parsed code block */ public void visitCode(Code obj) { stack.resetForMethodEntry(this); collectionGroups.clear(); - iteratorToGroup.clear(); + groupToIterator.clear(); + loops.clear(); super.visitCode(obj); } @@ -116,25 +121,48 @@ if (seen == INVOKEINTERFACE) { String className = getClassConstantOperand(); + String methodName = getNameConstantOperand(); + String signature = getSigConstantOperand(); + String methodInfo = methodName + signature; + 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); + groupId = findCollectionGroup(itm, true); } } else if ("iterator()Ljava/util/Iterator;".equals(methodInfo)) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); - groupId = findCollectionGroup(itm); - + groupId = findCollectionGroup(itm, true); } } else if ("remove(Ljava/lang/Object;)Z".equals(methodInfo)) { - + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + int id = findCollectionGroup(itm, true); + if (id >= 0) { + Integer it = groupToIterator.get(id); + Loop loop = loops.get(it); + if (loop != null) { + int pc = getPC(); + if (loop.hasPC(pc)) { + bugReporter.reportBug(new BugInstance(this, "DWI_DELETING_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) { + OpcodeStack.Item itm = stack.getStackItem(0); + Integer id = (Integer)itm.getUserValue(); + if (id != null) + groupId = id.intValue(); + } } } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { if (stack.getStackDepth() > 0) { @@ -145,19 +173,34 @@ 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)); - } + groupToIterator.put(id, Integer14.valueOf(reg)); } + + Set<Comparable> group = collectionGroups.get(id); + if (group != null) { + group.add(Integer14.valueOf(reg)); + } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } } } - + } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { + int reg = RegisterUtils.getALoadReg(this, seen); + OpcodeStack.Item itm = new OpcodeStack.Item(new OpcodeStack.Item(), reg); + groupId = findCollectionGroup(itm, false); + } else if (seen == IFEQ) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + Integer id = (Integer)itm.getUserValue(); + if (id != null) { + int target = getBranchTarget(); + int gotoAddr = target - 3; + if (getCode().getCode()[gotoAddr] == GOTO) { + loops.put(id, new Loop(getPC(), gotoAddr)); + } + } + } } } finally { stack.sawOpcode(this, seen); @@ -179,7 +222,7 @@ } } - private int findCollectionGroup(OpcodeStack.Item itm) { + private int findCollectionGroup(OpcodeStack.Item itm, boolean addIfNotFound) { Comparable groupElement = null; Integer id = (Integer)itm.getUserValue(); @@ -205,12 +248,37 @@ } } - Set<Comparable> group = new HashSet<Comparable>(); - group.add(groupElement); - collectionGroups.add(group); - return collectionGroups.size() - 1; + if (addIfNotFound) { + Set<Comparable> group = new HashSet<Comparable>(); + group.add(groupElement); + collectionGroups.add(group); + return collectionGroups.size() - 1; + } } return -1; } + + class Loop + { + public int loopStart; + public int loopFinish; + + public Loop(int start, int finish) { + loopStart = start; + loopFinish = finish; + } + + public int getLoopFinish() { + return loopFinish; + } + + public int getLoopStart() { + return loopStart; + } + + public boolean hasPC(int pc) { + return (loopStart <= pc) && (pc <= loopFinish); + } + } } 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-17 07:56:43
|
Revision: 736 http://svn.sourceforge.net/fb-contrib/?rev=736&view=rev Author: dbrosius Date: 2006-12-16 23:53:07 -0800 (Sat, 16 Dec 2006) Log Message: ----------- warnings Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2006-12-17 07:47:05 UTC (rev 735) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2006-12-17 07:53:07 UTC (rev 736) @@ -27,8 +27,6 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; -import edu.umd.cs.findbugs.FindBugsAnalysisFeatures; -import edu.umd.cs.findbugs.ba.AnalysisContext; import edu.umd.cs.findbugs.ba.ClassContext; /** Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2006-12-17 07:47:05 UTC (rev 735) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2006-12-17 07:53:07 UTC (rev 736) @@ -121,6 +121,7 @@ * @param obj the code that is currently being parsed */ @Override + @SuppressWarnings("unchecked") public void visitCode(final Code obj) { stack.resetForMethodEntry(this); thisClsAccessCount = 0; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java 2006-12-17 07:47:05 UTC (rev 735) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java 2006-12-17 07:53:07 UTC (rev 736) @@ -133,6 +133,7 @@ * * @return whether the code blocks are the same */ + @SuppressWarnings("deprecation") public boolean codeEquals(Code child, Code parent) { byte[] childBytes = child.getCode(); byte[] parentBytes = parent.getCode(); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-12-17 07:47:05 UTC (rev 735) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-12-17 07:53:07 UTC (rev 736) @@ -29,7 +29,6 @@ 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; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-17 07:50:42
|
Revision: 735 http://svn.sourceforge.net/fb-contrib/?rev=735&view=rev Author: dbrosius Date: 2006-12-16 23:47:05 -0800 (Sat, 16 Dec 2006) Log Message: ----------- warnings Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java 2006-12-17 07:41:11 UTC (rev 734) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java 2006-12-17 07:47:05 UTC (rev 735) @@ -1,12 +1,10 @@ package com.mebigfatguy.fbcontrib.collect; import org.apache.bcel.classfile.Code; -import org.apache.bcel.classfile.Method; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.NonReportingDetector; -import edu.umd.cs.findbugs.ba.ClassContext; public class CollectStatistics extends BytecodeScanningDetector implements NonReportingDetector { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2006-12-17 07:41:11 UTC (rev 734) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2006-12-17 07:47:05 UTC (rev 735) @@ -366,8 +366,8 @@ if (depth == 0) return true; - int dot1 = packName1.indexOf("."); - int dot2 = packName2.indexOf("."); + int dot1 = packName1.indexOf('.'); + int dot2 = packName2.indexOf('.'); if (dot1 < 0) return (dot2 < 0); else if (dot2 < 0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-17 07:45:14
|
Revision: 734 http://svn.sourceforge.net/fb-contrib/?rev=734&view=rev Author: dbrosius Date: 2006-12-16 23:41:11 -0800 (Sat, 16 Dec 2006) Log Message: ----------- remove useless method Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java 2006-12-17 07:39:20 UTC (rev 733) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java 2006-12-17 07:41:11 UTC (rev 734) @@ -17,11 +17,6 @@ } @Override - public void visitClassContext(ClassContext classContext) { - super.visitClassContext(classContext); - } - - @Override public void visitCode(Code obj) { numMethodCalls = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-17 07:44:22
|
Revision: 733 http://svn.sourceforge.net/fb-contrib/?rev=733&view=rev Author: dbrosius Date: 2006-12-16 23:39:20 -0800 (Sat, 16 Dec 2006) Log Message: ----------- LSC fixes Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2006-12-17 06:32:52 UTC (rev 732) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2006-12-17 07:39:20 UTC (rev 733) @@ -31,7 +31,7 @@ JavaClass[] supers = cls.getSuperClasses(); for (int i = 0; i < supers.length; i++) { - if (supers[i].getClassName().equals("java.lang.Object")) { + if ("java.lang.Object".equals(supers[i].getClassName())) { supers[i] = null; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-17 06:39:27
|
Revision: 732 http://svn.sourceforge.net/fb-contrib/?rev=732&view=rev Author: dbrosius Date: 2006-12-16 22:32:52 -0800 (Sat, 16 Dec 2006) Log Message: ----------- when removing child scopes, always push up the load/stores Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-16 09:06:19 UTC (rev 731) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-17 06:32:52 UTC (rev 732) @@ -195,6 +195,7 @@ if ((sb != null) && (!sb.isLoop) && !sb.hasChildren()) { if (sb.isGoto()) { ScopeBlock parent = sb.getParent(); + sb.pushUpLoadStores(); if (parent != null) parent.removeChild(sb); sb = new ScopeBlock(getPC(), target); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-16 09:06:20
|
Revision: 731 http://svn.sourceforge.net/fb-contrib/?rev=731&view=rev Author: dbrosius Date: 2006-12-16 01:06:19 -0800 (Sat, 16 Dec 2006) Log Message: ----------- if a variable is used in a parent scope, don't report on it at a child scope. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-16 07:34:52 UTC (rev 730) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-16 09:06:19 UTC (rev 731) @@ -114,7 +114,7 @@ super.visitCode(obj); if (!dontReport) - rootScopeBlock.findBugs(); + rootScopeBlock.findBugs(new HashSet<Integer>()); } finally { rootScopeBlock = null; @@ -473,40 +473,50 @@ /** * report stores that occur at scopes higher than associated loads that are not involved with loops */ - public void findBugs() { + public void findBugs(Set<Integer> parentUsedRegs) { if (isLoop) return; + Set<Integer> usedRegs = new HashSet<Integer>(parentUsedRegs); + if (stores != null) + usedRegs.addAll(stores.keySet()); + if (loads != null) + usedRegs.addAll(loads.keySet()); + if (stores != null) { if (loads != null) stores.keySet().removeAll(loads.keySet()); + stores.keySet().removeAll(parentUsedRegs); - if (children != null) { - for (Map.Entry<Integer, Integer> entry : stores.entrySet()) { - int childUseCount = 0; - boolean inLoop = false; - for (ScopeBlock child : children) { - if (child.usesReg(entry.getKey())) { - if (child.isLoop) { - inLoop = true; - break; - } - childUseCount++; - } - } - if ((!inLoop) && (childUseCount == 1)) { - bugReporter.reportBug(new BugInstance(BloatedAssignmentScope.this, "BAS_BLOATED_ASSIGNMENT_SCOPE", NORMAL_PRIORITY) - .addClass(BloatedAssignmentScope.this) - .addMethod(BloatedAssignmentScope.this) - .addSourceLine(BloatedAssignmentScope.this, entry.getValue())); - } - } - } + if (stores.size() > 0) { + if (children != null) { + for (Map.Entry<Integer, Integer> entry : stores.entrySet()) { + int childUseCount = 0; + boolean inLoop = false; + Integer reg = entry.getKey(); + for (ScopeBlock child : children) { + if (child.usesReg(reg)) { + if (child.isLoop) { + inLoop = true; + break; + } + childUseCount++; + } + } + if ((!inLoop) && (childUseCount == 1)) { + bugReporter.reportBug(new BugInstance(BloatedAssignmentScope.this, "BAS_BLOATED_ASSIGNMENT_SCOPE", NORMAL_PRIORITY) + .addClass(BloatedAssignmentScope.this) + .addMethod(BloatedAssignmentScope.this) + .addSourceLine(BloatedAssignmentScope.this, entry.getValue())); + } + } + } + } } if (children != null) { for (ScopeBlock child : children) { - child.findBugs(); + child.findBugs(usedRegs); } } } 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-14 06:40:37
|
Revision: 729 http://svn.sourceforge.net/fb-contrib/?rev=729&view=rev Author: dbrosius Date: 2006-12-13 22:40:36 -0800 (Wed, 13 Dec 2006) Log Message: ----------- When looking for a scope block with target, if one is found, don't automatically return it, but look for smaller children first. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-14 00:05:21 UTC (rev 728) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-14 06:40:36 UTC (rev 729) @@ -273,9 +273,10 @@ * @return the scope block found or null */ private ScopeBlock findScopeBlockWithTarget(ScopeBlock sb, int start, int target) { + ScopeBlock parentBlock = null; if ((sb.startLocation < start) && (sb.finishLocation >= start)) { if ((sb.finishLocation <= target) || (sb.isGoto() && !sb.isLoop())) - return sb; + parentBlock = sb; } if (sb.children != null) @@ -287,7 +288,7 @@ } } - return null; + return parentBlock; } /** holds the description of a scope { } block, be it a for, if, while block This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-14 00:05:21
|
Revision: 728 http://svn.sourceforge.net/fb-contrib/?rev=728&view=rev Author: dbrosius Date: 2006-12-13 16:05:21 -0800 (Wed, 13 Dec 2006) Log Message: ----------- engrish Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-12-13 16:46:58 UTC (rev 727) +++ trunk/fb-contrib/etc/messages.xml 2006-12-14 00:05:21 UTC (rev 728) @@ -1398,7 +1398,7 @@ <LongDescription>Method {1} creates array using constants</LongDescription> <Details> <![CDATA[ - <p>This method creates an initialized by constants. Each time this method is called + <p>This method creates an array initialized by constants. Each time this method is called this array will be recreated. It would be more performant to define the array as a static field of the class instead.</p> ]]> 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-13 05:37:49
|
Revision: 726 http://svn.sourceforge.net/fb-contrib/?rev=726&view=rev Author: dbrosius Date: 2006-12-12 21:37:35 -0800 (Tue, 12 Dec 2006) Log Message: ----------- reset xmlConfidentCount on method entry... oops Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java 2006-12-13 04:40:01 UTC (rev 725) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java 2006-12-13 05:37:35 UTC (rev 726) @@ -100,6 +100,7 @@ public void visitCode(Code obj) { stack.resetForMethodEntry(this); xmlItemCount = 0; + xmlConfidentCount = 0; firstPC = -1; super.visitCode(obj); if ((xmlItemCount >= lowReportingThreshold) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-13 04:40:05
|
Revision: 725 http://svn.sourceforge.net/fb-contrib/?rev=725&view=rev Author: dbrosius Date: 2006-12-12 20:40:01 -0800 (Tue, 12 Dec 2006) Log Message: ----------- add switch blocks as scope blocks, don't add the goto's at the end of the case blocks. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-12 15:17:26 UTC (rev 724) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-13 04:40:01 UTC (rev 725) @@ -19,6 +19,7 @@ package com.mebigfatguy.fbcontrib.detect; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -47,6 +48,7 @@ private Set<Integer> ignoreRegs; private ScopeBlock rootScopeBlock; private Set<Integer> catchHandlers; + private Set<Integer> switchTargets; private boolean dontReport; private boolean sawDup; @@ -69,10 +71,12 @@ try { ignoreRegs = new HashSet<Integer>(); catchHandlers = new HashSet<Integer>(); + switchTargets = new HashSet<Integer>(); super.visitClassContext(classContext); } finally { ignoreRegs = null; catchHandlers = null; + switchTargets = null; } } @@ -104,7 +108,7 @@ } } - + switchTargets.clear(); dontReport = false; sawDup = false; super.visitCode(obj); @@ -172,17 +176,20 @@ int target = getBranchTarget(); if (target > getPC()) { if ((seen == GOTO) || (seen == GOTO_W)) { - ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), getNextPC()); - if (sb == null) { - sb = new ScopeBlock(getPC(), target); - sb.setLoop(); - sb.setGoto(); - rootScopeBlock.addChild(sb); - } else { - sb = new ScopeBlock(getPC(), target); - sb.setGoto(); - rootScopeBlock.addChild(sb); - } + Integer nextPC = Integer.valueOf(getNextPC()); + if (!switchTargets.contains(nextPC)) { + ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), getNextPC()); + if (sb == null) { + sb = new ScopeBlock(getPC(), target); + sb.setLoop(); + sb.setGoto(); + rootScopeBlock.addChild(sb); + } else { + sb = new ScopeBlock(getPC(), target); + sb.setGoto(); + rootScopeBlock.addChild(sb); + } + } } else { ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), target); if ((sb != null) && (!sb.isLoop) && !sb.hasChildren()) { @@ -207,6 +214,25 @@ if (sb != null) sb.setLoop(); } + } else if ((seen == TABLESWITCH) || (seen == LOOKUPSWITCH)) { + int pc = getPC(); + int[] offsets = getSwitchOffsets(); + List<Integer> targets = new ArrayList<Integer>(); + for (int i = 0; i < offsets.length; i++) + targets.add(Integer.valueOf(offsets[i] + pc)); + Integer defOffset = Integer.valueOf(getDefaultSwitchOffset() + pc); + if (!targets.contains(defOffset)) + targets.add(defOffset); + Collections.sort(targets); + + Integer lastTarget = targets.get(0); + for (int i = 1; i < targets.size(); i++) { + Integer nextTarget = targets.get(i); + ScopeBlock sb = new ScopeBlock(lastTarget.intValue(), nextTarget.intValue()); + rootScopeBlock.addChild(sb); + lastTarget = nextTarget; + } + switchTargets.addAll(targets); } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEVIRTUAL)) { if ("wasNull".equals(getNameConstantOperand()) && "()Z".equals(getSigConstantOperand())) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-12 15:17:28
|
Revision: 724 http://svn.sourceforge.net/fb-contrib/?rev=724&view=rev Author: dbrosius Date: 2006-12-12 07:17:26 -0800 (Tue, 12 Dec 2006) Log Message: ----------- Modified Paths: -------------- trunk/fb-contrib/samples/BAS_Sample.java Modified: trunk/fb-contrib/samples/BAS_Sample.java =================================================================== --- trunk/fb-contrib/samples/BAS_Sample.java 2006-12-12 07:50:42 UTC (rev 723) +++ trunk/fb-contrib/samples/BAS_Sample.java 2006-12-12 15:17:26 UTC (rev 724) @@ -1,3 +1,4 @@ +import java.util.List; public class BAS_Sample { @@ -45,5 +46,46 @@ return s; } + + public String testFPLoopCond(List<String> in) + { + StringBuilder sb = new StringBuilder(); + for (String s : in) + { + sb.append(s); + } + return sb.toString(); + } + + public List<String> getList() + { + return null; + } + + public String testSwitch(int a) + { + String v = "Test"; + + switch (a) + { + case 1: + v = "Testa"; + break; + + case 2: + v = "Tesseract"; + break; + + case 3: + v = "Testy"; + break; + + default: + v = "Rossa"; + break; + } + return null; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-12 07:58:25
|
Revision: 723 http://svn.sourceforge.net/fb-contrib/?rev=723&view=rev Author: dbrosius Date: 2006-12-11 23:50:42 -0800 (Mon, 11 Dec 2006) Log Message: ----------- if a dup occurs before a store, assume it's a load as well. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-12 07:36:16 UTC (rev 722) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-12 07:50:42 UTC (rev 723) @@ -48,6 +48,7 @@ private ScopeBlock rootScopeBlock; private Set<Integer> catchHandlers; private boolean dontReport; + private boolean sawDup; /** * constructs a BAS detector given the reporter to report bugs on @@ -105,6 +106,7 @@ dontReport = false; + sawDup = false; super.visitCode(obj); if (!dontReport) @@ -135,16 +137,19 @@ || ((seen >= DSTORE_0) && (seen <= DSTORE_1))) { int reg = RegisterUtils.getStoreReg(this, seen); Integer iReg = Integer.valueOf(reg); - if (catchHandlers.contains(getPC())) + int pc = getPC(); + if (catchHandlers.contains(pc)) ignoreRegs.add(iReg); if (!ignoreRegs.contains(iReg)) { - ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC()); - if (sb != null) - sb.addStore(reg, getPC()); + ScopeBlock sb = findScopeBlock(rootScopeBlock, pc); + if (sb != null) { + sb.addStore(reg, pc); + if (sawDup) + sb.addLoad(reg, pc); + } else ignoreRegs.add(iReg); } - } else if ((seen == ALOAD) || (seen == ILOAD) || (seen == LLOAD) @@ -206,7 +211,9 @@ if ("wasNull".equals(getNameConstantOperand()) && "()Z".equals(getSigConstantOperand())) dontReport = true; - } + } + + sawDup = (seen == DUP); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-12 07:43:05
|
Revision: 722 http://svn.sourceforge.net/fb-contrib/?rev=722&view=rev Author: dbrosius Date: 2006-12-11 23:36:16 -0800 (Mon, 11 Dec 2006) Log Message: ----------- create a scope block for the end of if block goto temporarily, so that an unguarded else is blocked. But if a scope block is found to this goto block, then remove it, as we've found an else if Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-12 04:35:24 UTC (rev 721) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-12 07:36:16 UTC (rev 722) @@ -171,14 +171,27 @@ if (sb == null) { sb = new ScopeBlock(getPC(), target); sb.setLoop(); + sb.setGoto(); rootScopeBlock.addChild(sb); + } else { + sb = new ScopeBlock(getPC(), target); + sb.setGoto(); + rootScopeBlock.addChild(sb); } } else { ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), target); if ((sb != null) && (!sb.isLoop) && !sb.hasChildren()) { - sb.pushUpLoadStores(); - sb.setStart(getPC()); - sb.setFinish(target); + if (sb.isGoto()) { + ScopeBlock parent = sb.getParent(); + if (parent != null) + parent.removeChild(sb); + sb = new ScopeBlock(getPC(), target); + rootScopeBlock.addChild(sb); + } else { + sb.pushUpLoadStores(); + sb.setStart(getPC()); + sb.setFinish(target); + } } else { sb = new ScopeBlock(getPC(), target); rootScopeBlock.addChild(sb); @@ -227,8 +240,10 @@ * @return the scope block found or null */ private ScopeBlock findScopeBlockWithTarget(ScopeBlock sb, int start, int target) { - if ((sb.startLocation < start) && (sb.finishLocation >= start) && (sb.finishLocation <= target)) - return sb; + if ((sb.startLocation < start) && (sb.finishLocation >= start)) { + if ((sb.finishLocation <= target) || (sb.isGoto() && !sb.isLoop())) + return sb; + } if (sb.children != null) { @@ -250,6 +265,7 @@ private int startLocation; private int finishLocation; private boolean isLoop; + private boolean isGoto; private Map<Integer, Integer> loads; private Map<Integer, Integer> stores; private List<ScopeBlock> children; @@ -264,6 +280,7 @@ startLocation = start; finishLocation = finish; isLoop = false; + isGoto = false; loads = null; stores = null; children = null; @@ -278,6 +295,15 @@ return "Start=" + startLocation + " Finish=" + finishLocation + " Loop=" + isLoop + " Loads=" + loads + " Stores=" + stores; } + /** + * returns the scope blocks parent + * + * @return the parent of this scope block + */ + public ScopeBlock getParent() { + return parent; + } + /** returns the start of the block * * @return the start of the block @@ -319,6 +345,31 @@ public void setLoop() { isLoop = true; } + + /** + * returns whether this scope block is a loop + * + * @returns whether this block is a loop + */ + public boolean isLoop() { + return isLoop; + } + + /** + * sets that this block was caused from a goto, (an if block exit) + */ + public void setGoto() { + isGoto = true; + } + + /** + * returns whether this block was caused from a goto + * + * @returns whether this block was caused by a goto + */ + public boolean isGoto() { + return isGoto; + } /** * adds the register as a store in this scope block @@ -376,6 +427,15 @@ children.add(newChild); } + /** + * removes a child from this node + * @param child the child to remove + */ + public void removeChild(ScopeBlock child) { + if (children != null) + children.remove(child); + } + /** * report stores that occur at scopes higher than associated loads that are not involved with loops */ 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-10 10:18:42
|
Revision: 720 http://svn.sourceforge.net/fb-contrib/?rev=720&view=rev Author: dbrosius Date: 2006-12-10 02:18:38 -0800 (Sun, 10 Dec 2006) Log Message: ----------- don't report catch block stores Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-10 09:25:19 UTC (rev 719) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-10 10:18:38 UTC (rev 720) @@ -26,6 +26,7 @@ import java.util.Set; import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.CodeException; import org.apache.bcel.classfile.Method; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; @@ -45,6 +46,7 @@ BugReporter bugReporter; private Set<Integer> ignoreRegs; private ScopeBlock rootScopeBlock; + private Set<Integer> catchHandlers; private boolean dontReport; /** @@ -65,9 +67,11 @@ public void visitClassContext(ClassContext classContext) { try { ignoreRegs = new HashSet<Integer>(); + catchHandlers = new HashSet<Integer>(); super.visitClassContext(classContext); } finally { ignoreRegs = null; + catchHandlers = null; } } @@ -91,6 +95,15 @@ } rootScopeBlock = new ScopeBlock(0, obj.getLength()); + catchHandlers.clear(); + CodeException[] exceptions = obj.getExceptionTable(); + if (exceptions != null) { + for (CodeException ex : exceptions) { + catchHandlers.add(Integer.valueOf(ex.getHandlerPC())); + } + } + + dontReport = false; super.visitCode(obj); @@ -121,12 +134,15 @@ || ((seen >= FSTORE_0) && (seen <= FSTORE_1)) || ((seen >= DSTORE_0) && (seen <= DSTORE_1))) { int reg = RegisterUtils.getStoreReg(this, seen); - if (!ignoreRegs.contains(Integer.valueOf(reg))) { + Integer iReg = Integer.valueOf(reg); + if (catchHandlers.contains(getPC())) + ignoreRegs.add(iReg); + if (!ignoreRegs.contains(iReg)) { ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC()); if (sb != null) sb.addStore(reg, getPC()); else - ignoreRegs.add(Integer.valueOf(reg)); + ignoreRegs.add(iReg); } } else if ((seen == ALOAD) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-10 09:25:19
|
Revision: 719 http://svn.sourceforge.net/fb-contrib/?rev=719&view=rev Author: dbrosius Date: 2006-12-10 01:25:19 -0800 (Sun, 10 Dec 2006) Log Message: ----------- the ResultSet.wasNull method is problematic, so if a method uses it, don't report. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-10 09:14:38 UTC (rev 718) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-10 09:25:19 UTC (rev 719) @@ -45,6 +45,7 @@ BugReporter bugReporter; private Set<Integer> ignoreRegs; private ScopeBlock rootScopeBlock; + private boolean dontReport; /** * constructs a BAS detector given the reporter to report bugs on @@ -90,9 +91,11 @@ } rootScopeBlock = new ScopeBlock(0, obj.getLength()); + dontReport = false; super.visitCode(obj); - rootScopeBlock.findBugs(); + if (!dontReport) + rootScopeBlock.findBugs(); } finally { rootScopeBlock = null; @@ -170,7 +173,11 @@ if (sb != null) sb.setLoop(); } - } + } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEVIRTUAL)) { + if ("wasNull".equals(getNameConstantOperand()) + && "()Z".equals(getSigConstantOperand())) + dontReport = true; + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-10 09:14:44
|
Revision: 718 http://svn.sourceforge.net/fb-contrib/?rev=718&view=rev Author: dbrosius Date: 2006-12-10 01:14:38 -0800 (Sun, 10 Dec 2006) Log Message: ----------- don't create a scope block on a GOTO at the end of an if block (before an else) Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-10 07:16:06 UTC (rev 717) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-10 09:14:38 UTC (rev 718) @@ -149,11 +149,8 @@ if (target > getPC()) { if ((seen == GOTO) || (seen == GOTO_W)) { ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), getNextPC()); - if (sb != null) { + if (sb == null) { sb = new ScopeBlock(getPC(), target); - rootScopeBlock.addChild(sb); - } else { - sb = new ScopeBlock(getPC(), target); sb.setLoop(); rootScopeBlock.addChild(sb); } @@ -207,7 +204,7 @@ * @return the scope block found or null */ private ScopeBlock findScopeBlockWithTarget(ScopeBlock sb, int start, int target) { - if ((sb.startLocation < start) && (sb.finishLocation <= target)) + if ((sb.startLocation < start) && (sb.finishLocation >= start) && (sb.finishLocation <= target)) return sb; if (sb.children != null) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |