fb-contrib-commit Mailing List for fb-contrib (Page 76)
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: Dave B. <dbr...@us...> - 2005-09-22 05:45:21
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19588/src/com/mebigfatguy/fbcontrib/detect Modified Files: DubiousListCollection.java Log Message: if a method is called on an implementing List class, rather than the interface, then remove it from consideration Index: DubiousListCollection.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- DubiousListCollection.java 22 Sep 2005 05:32:16 -0000 1.2 +++ DubiousListCollection.java 22 Sep 2005 05:45:13 -0000 1.3 @@ -98,30 +98,45 @@ String signature = getSigConstantOperand(); if (className.startsWith("java/util/") && className.endsWith("List")) { - int parmCount = Type.getArgumentTypes(signature).length; - if (stack.getStackDepth() > parmCount) { - OpcodeStack.Item itm = stack.getStackItem(parmCount); - FieldAnnotation fa = itm.getField(); - if (fa != null) { - String field = fa.getFieldName(); - Integer cnt = fieldsReported.get(field); - if (cnt != null) { - String methodInfo = methodName + signature; - if (listMethods.contains(methodInfo)) - fieldsReported.remove(field); - else if (setMethods.contains(methodInfo)) { - cnt = new Integer(cnt.intValue() + 1); - fieldsReported.put(field, cnt); - } + FieldAnnotation fa = getFieldFromStack(stack, signature); + if (fa != null) { + String field = fa.getFieldName(); + Integer cnt = fieldsReported.get(field); + if (cnt != null) { + String methodInfo = methodName + signature; + if (listMethods.contains(methodInfo)) + fieldsReported.remove(field); + else if (setMethods.contains(methodInfo)) { + cnt = new Integer(cnt.intValue() + 1); + fieldsReported.put(field, cnt); } } } } + } 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); + } + } } } finally { stack.sawOpcode(this, seen); } } + + private FieldAnnotation getFieldFromStack(OpcodeStack stk, String signature) { + int parmCount = Type.getArgumentTypes(signature).length; + if (stk.getStackDepth() > parmCount) { + OpcodeStack.Item itm = stk.getStackItem(parmCount); + FieldAnnotation fa = itm.getField(); + return fa; + } + return null; + } private void reportBugs() { for (Map.Entry<String, Integer> entry : fieldsReported.entrySet()) { |
From: Dave B. <dbr...@us...> - 2005-09-22 05:34:28
|
Update of /cvsroot/fb-contrib/fb-contrib/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17375/lib Modified Files: bcel.jar Log Message: update to latest Index: bcel.jar =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/lib/bcel.jar,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 Binary files /tmp/cvsMJn9vp and /tmp/cvsmPjkU2 differ |
From: Dave B. <dbr...@us...> - 2005-09-22 05:32:25
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17916/src/com/mebigfatguy/fbcontrib/detect Modified Files: DubiousListCollection.java Log Message: add copyright Index: DubiousListCollection.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- DubiousListCollection.java 22 Sep 2005 05:28:29 -0000 1.1 +++ DubiousListCollection.java 22 Sep 2005 05:32:16 -0000 1.2 @@ -1,3 +1,21 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005 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; |
From: Dave B. <dbr...@us...> - 2005-09-22 05:28:37
|
Update of /cvsroot/fb-contrib/fb-contrib/etc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17178/etc Modified Files: findbugs.xml messages.xml Log Message: Initial Checkin: New detector DLC, find members declared as Lists that probably should be defined as Sets Index: messages.xml =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/etc/messages.xml,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- messages.xml 20 Sep 2005 02:28:42 -0000 1.14 +++ messages.xml 22 Sep 2005 05:28:28 -0000 1.15 @@ -115,9 +115,10 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.FinalParameters"> <Details> <![CDATA[ - <p> Looks for methods that do not write to parameters, but do not declare these parameters final. - Doing so helps document the behaviour of the method, and may help the jvm to optimize the method - call.</p> + <p> Looks for classes that define fields that derive from java.util.List but are used to some extent + like a set class. Because set-type operations are performed using a linear search, performance is + going to be inferior to a Set class. If this List is going to remain very small, this may not + be a problem, but if the List may grow large, performance will suffer significantly.</p> <p>It is a fast detector</p> ]]> </Details> @@ -145,6 +146,17 @@ </Details> </Detector> + <Detector class="com.mebigfatguy.fbcontrib.detect.DubiousListCollection"> + <Details> + <![CDATA[ + <p> Looks for constructors of non final classes that make method calls to non final methods. + As these methods could be overridden, the overridden method will be accessing an object that + is only partially constructed, perhaps causing problems.</p> + <p>It is a fast detector</p> + ]]> + </Details> + </Detector> + <!-- BugPattern --> <BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING"> @@ -282,6 +294,18 @@ </Details> </BugPattern> + <BugPattern type="DLC_DUBIOUS_LIST_COLLECTION"> + <ShortDescription>class defines List based fields but uses them like Sets</ShortDescription> + <LongDescription>class {0} defines List based fields but uses them like Sets</LongDescription> + <Details> + <![CDATA[ + <p>This class defines a field based on java.util.List, but uses it to some extent like a Set. Since + lookup type operations are performed using a linear search for Lists, the performance for large + Lists will be poor. Consider changing this fields implementation to a set based one.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -295,5 +319,6 @@ <BugCode abbrev="FP">Final Parameters</BugCode> <BugCode abbrev="LSC">Literal String Comparison</BugCode> <BugCode abbrev="PCOA">Partially Constructed Object Access</BugCode> + <BugCode abbrev="DLC">Dubious List Collection</BugCode> </MessageCollection> \ No newline at end of file Index: findbugs.xml =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/etc/findbugs.xml,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- findbugs.xml 20 Sep 2005 02:28:42 -0000 1.15 +++ findbugs.xml 22 Sep 2005 05:28:28 -0000 1.16 @@ -58,6 +58,11 @@ speed="fast" reports="PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.DubiousListCollection" + speed="fast" + reports="DLC_DUBIOUS_LIST_COLLECTION" + hidden="true" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -71,5 +76,6 @@ <BugPattern abbrev="FP" type="FP_FINAL_PARAMETERS" category="STYLE" experimental="true" /> <BugPattern abbrev="LSC" type="LSC_LITERAL_STRING_COMPARISON" category="STYLE" experimental="true" /> <BugPattern abbrev="PCOA" type="PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="DLC" type="DLC_DUBIOUS_LIST_COLLECTION" category="PERFORMANCE" experimental="true" /> </FindbugsPlugin> \ No newline at end of file |
From: Dave B. <dbr...@us...> - 2005-09-22 05:28:37
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17178/src/com/mebigfatguy/fbcontrib/detect Added Files: DubiousListCollection.java Log Message: Initial Checkin: New detector DLC, find members declared as Lists that probably should be defined as Sets --- NEW FILE: DubiousListCollection.java --- package com.mebigfatguy.fbcontrib.detect; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.apache.bcel.Constants; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.Field; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.generic.Type; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.FieldAnnotation; import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.ba.ClassContext; public class DubiousListCollection extends BytecodeScanningDetector { private static final Integer FIELD_UNKNOWN = new Integer(0); private static Set<String> setMethods = new HashSet<String>(); private static Set<String> listMethods = new HashSet<String>(); static { setMethods.add("contains(Ljava/lang/Object;)Z"); setMethods.add("containsAll(Ljava/util/Collection;)Z"); setMethods.add("remove(Ljava/lang/Object;)Ljava/lang/Object;"); setMethods.add("removeAll(Ljava/util/Collection;)Z"); setMethods.add("retainAll(Ljava/util/Collection;)Z"); listMethods.add("add(ILjava/lang/Object;)V"); listMethods.add("addAll(ILjava/util/Collection;)Z"); listMethods.add("lastIndexOf(Ljava/lang/Object;)I"); listMethods.add("remove(I)Ljava/lang/Object;"); listMethods.add("set(ILjava/lang/Object;)Ljava/lang/Object;"); listMethods.add("subList(II)Ljava/util/List;"); //Theoretically get(i) and indexOf(Object) are setMethods but are so abused, as to be meaningless } private BugReporter bugReporter; private OpcodeStack stack = new OpcodeStack(); private Map<String, Integer> fieldsReported = new HashMap<String, Integer>(); public DubiousListCollection(BugReporter bugReporter) { this.bugReporter = bugReporter; } public void visitClassContext(ClassContext classContext) { JavaClass cls = classContext.getJavaClass(); Field[] flds = cls.getFields(); for (Field f : flds) { String sig = f.getSignature(); if (sig.charAt(0) == 'L') { sig = sig.substring(1, sig.length() - 1); if (sig.startsWith("java/util/") && sig.endsWith("List")) { fieldsReported.put(f.getName(), FIELD_UNKNOWN); } } } if (fieldsReported.size() > 0) { super.visitClassContext(classContext); reportBugs(); } } public void visitCode(Code obj) { stack.resetForMethodEntry(this); super.visitCode(obj); } public void sawOpcode(int seen) { try { if (seen == INVOKEINTERFACE) { String className = this.getClassConstantOperand(); String methodName = getNameConstantOperand(); String signature = getSigConstantOperand(); if (className.startsWith("java/util/") && className.endsWith("List")) { int parmCount = Type.getArgumentTypes(signature).length; if (stack.getStackDepth() > parmCount) { OpcodeStack.Item itm = stack.getStackItem(parmCount); FieldAnnotation fa = itm.getField(); if (fa != null) { String field = fa.getFieldName(); Integer cnt = fieldsReported.get(field); if (cnt != null) { String methodInfo = methodName + signature; if (listMethods.contains(methodInfo)) fieldsReported.remove(field); else if (setMethods.contains(methodInfo)) { cnt = new Integer(cnt.intValue() + 1); fieldsReported.put(field, cnt); } } } } } } } finally { stack.sawOpcode(this, seen); } } private void reportBugs() { for (Map.Entry<String, Integer> entry : fieldsReported.entrySet()) { String field = entry.getKey(); int cnt = entry.getValue().intValue(); if (cnt > 0) { FieldAnnotation fa = getFieldAnnotation(field); if (fa != null) { bugReporter.reportBug(new BugInstance(this, "DLC_DUBIOUS_LIST_COLLECTION", NORMAL_PRIORITY) .addClass(this) .addField(fa)); } } } } private FieldAnnotation getFieldAnnotation(String fieldName) { JavaClass cls = getClassContext().getJavaClass(); Field[] fields = cls.getFields(); for (Field f : fields) { if (f.getName().equals(fieldName)) return new FieldAnnotation(cls.getClassName(), fieldName, f.getSignature(), (f.getAccessFlags() & Constants.ACC_STATIC) != 0); } return null; //shouldn't happen } } |
From: Dave B. <dbr...@us...> - 2005-09-22 05:28:37
|
Update of /cvsroot/fb-contrib/fb-contrib/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17178/samples Added Files: DLC_Sample.java Log Message: Initial Checkin: New detector DLC, find members declared as Lists that probably should be defined as Sets --- NEW FILE: DLC_Sample.java --- import java.util.ArrayList; import java.util.List; public class DLC_Sample { private List<String> badList = new ArrayList<String>(); private List<String> goodList = new ArrayList<String>(); public void test1(String s1, String s2) { if (badList.contains(s1)) badList.add(s2); for (int i = 0; i < badList.size(); i++) { String s3 = badList.get(i); if (badList.indexOf(s1+s2) >= 0) badList.remove(s3); } } public void test2(String s1, String s2) { int idx = goodList.indexOf(s1); goodList.set(idx, s2); } } |
From: Dave B. <dbr...@us...> - 2005-09-22 05:28:36
|
Update of /cvsroot/fb-contrib/fb-contrib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17178 Modified Files: .classpath Log Message: Initial Checkin: New detector DLC, find members declared as Lists that probably should be defined as Sets Index: .classpath =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/.classpath,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- .classpath 3 Sep 2005 22:55:16 -0000 1.2 +++ .classpath 22 Sep 2005 05:28:28 -0000 1.3 @@ -4,6 +4,6 @@ <classpathentry kind="src" path="src"/> <classpathentry kind="src" path="samples"/> <classpathentry sourcepath="O:/findbugs/src" kind="lib" path="O:/fb-contrib/lib/findbugs.jar"/> - <classpathentry kind="lib" path="O:/fb-contrib/lib/bcel.jar"/> + <classpathentry sourcepath="O:/jakarta-bcel/trunk/src/java" kind="lib" path="O:/fb-contrib/lib/bcel.jar"/> <classpathentry kind="output" path="classes"/> </classpath> |
From: Dave B. <dbr...@us...> - 2005-09-22 02:04:45
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17182/src/com/mebigfatguy/fbcontrib/detect Modified Files: OverlyConcreteParameter.java Log Message: add the (an) interface name to the bug report Index: OverlyConcreteParameter.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- OverlyConcreteParameter.java 11 Sep 2005 05:34:13 -0000 1.15 +++ OverlyConcreteParameter.java 22 Sep 2005 02:04:37 -0000 1.16 @@ -175,10 +175,11 @@ parm--; parm++; //users expect 1 based parameters + String infName = definers.keySet().iterator().next().getClassName(); bugReporter.reportBug( new BugInstance( this, "OCP_OVERLY_CONCRETE_PARAMETER", NORMAL_PRIORITY) .addClass(this) .addMethod(this) - .addString("Parameter [" + reg.intValue() + "] " + name)); + .addString("Parameter [" + reg.intValue() + "] " + name + " implements " + infName)); } } } |
From: Dave B. <dbr...@us...> - 2005-09-20 02:31:34
|
Update of /cvsroot/fb-contrib/fb-contrib/htdocs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29283/htdocs Modified Files: index.html Log Message: document PCOA Index: index.html =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/htdocs/index.html,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- index.html 19 Sep 2005 04:22:23 -0000 1.10 +++ index.html 20 Sep 2005 02:31:27 -0000 1.11 @@ -18,6 +18,10 @@ Detectors added in CVS<br/> Note: these detectors are still in testing<br/> <ul> + <li><b>Partially Constructed Object Access</b><br/> + Finds constructors that call non-final methods in non-final classes. If this class is derived from, and the + method is overridden, then that method will be executing on an object that hasn't been constructed in regards + to the subclass implementation. These methods should probably be defined as final.</li> <li><b>Literal String Comparison</b><br/> Finds methods that call the equals or compareTo methods on a String variable passing in a String literal. A NullPointerException may occur if the string variable is null. If instead the method was called on |
From: Dave B. <dbr...@us...> - 2005-09-20 02:28:50
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28847/src/com/mebigfatguy/fbcontrib/detect Added Files: PartiallyConstructedObjectAccess.java Log Message: Initial checkin: PCOA --- NEW FILE: PartiallyConstructedObjectAccess.java --- /* * fb-contrib - Auxilliary detectors for Java programs * Copyright (C) 2005 Dave Brosius * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.mebigfatguy.fbcontrib.detect; import org.apache.bcel.Constants; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.ba.ClassContext; public class PartiallyConstructedObjectAccess extends BytecodeScanningDetector { private BugReporter bugReporter; private OpcodeStack stack; private boolean reportedCtor; public PartiallyConstructedObjectAccess(BugReporter bugReporter) { this.bugReporter = bugReporter; stack = new OpcodeStack(); } public Object clone() throws CloneNotSupportedException { return super.clone(); } public void visitClassContext(ClassContext classContext) { JavaClass cls = classContext.getJavaClass(); if ((cls.getAccessFlags() & Constants.ACC_FINAL) == 0) super.visitClassContext(classContext); } public void visitCode(Code obj) { stack.resetForMethodEntry(this); reportedCtor = false; if ("<init>".equals(getMethodName())) super.visitCode(obj); } public void sawOpcode(int seen) { if (reportedCtor) return; try { if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE)) { int parmCount = Type.getArgumentTypes(getSigConstantOperand()).length; if (stack.getStackDepth() > parmCount) { OpcodeStack.Item itm = stack.getStackItem(parmCount); if (itm.getRegisterNumber() == 0) { JavaClass cls = itm.getJavaClass(); if (cls != null) { Method m = findMethod(cls, getNameConstantOperand(), getSigConstantOperand()); if (m != null) { if ((m.getAccessFlags() & Constants.ACC_FINAL) == 0) { bugReporter.reportBug( new BugInstance(this, "PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS", NORMAL_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(this, getPC())); reportedCtor = true; } } } } } } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } finally { stack.sawOpcode(this, seen); } } private Method findMethod(JavaClass cls, String methodName, String methodSig) { Method[] methods = cls.getMethods(); for (Method m : methods) { if (methodName.equals(m.getName()) && methodSig.equals(m.getSignature())) { return m; } } return null; } } |
From: Dave B. <dbr...@us...> - 2005-09-20 02:28:50
|
Update of /cvsroot/fb-contrib/fb-contrib/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28847/samples Added Files: PCOA_Sample.java Log Message: Initial checkin: PCOA --- NEW FILE: PCOA_Sample.java --- public class PCOA_Sample { public PCOA_Sample() { overridableMethod(); } public PCOA_Sample(int ok) { nonOverridableMethod(); } public void overridableMethod() { } public final void nonOverridableMethod() { } final static class FinalClass { public FinalClass() { aMethod(); } public void aMethod() { } } } |
From: Dave B. <dbr...@us...> - 2005-09-20 02:28:50
|
Update of /cvsroot/fb-contrib/fb-contrib/etc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28847/etc Modified Files: findbugs.xml messages.xml Log Message: Initial checkin: PCOA Index: messages.xml =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/etc/messages.xml,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- messages.xml 19 Sep 2005 04:20:20 -0000 1.13 +++ messages.xml 20 Sep 2005 02:28:42 -0000 1.14 @@ -134,6 +134,17 @@ </Details> </Detector> + <Detector class="com.mebigfatguy.fbcontrib.detect.PartiallyConstructedObjectAccess"> + <Details> + <![CDATA[ + <p> Looks for constructors of non final classes that make method calls to non final methods. + As these methods could be overridden, the overridden method will be accessing an object that + is only partially constructed, perhaps causing problems.</p> + <p>It is a fast detector</p> + ]]> + </Details> + </Detector> + <!-- BugPattern --> <BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING"> @@ -259,6 +270,18 @@ </Details> </BugPattern> + <BugPattern type="PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS"> + <ShortDescription>constructor makes call to non-final method</ShortDescription> + <LongDescription>constructor {1} makes call to non-final method</LongDescription> + <Details> + <![CDATA[ + <p>This constructor makes a call to a non-final method. Since this method can be overriden, a subclasses + implementation will be executing against an object that has not been initialized at the subclass level. + You should mark all methods called from the constructor as final to avoid this problem.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -271,5 +294,6 @@ <BugCode abbrev="CE">Class Envy</BugCode> <BugCode abbrev="FP">Final Parameters</BugCode> <BugCode abbrev="LSC">Literal String Comparison</BugCode> - + <BugCode abbrev="PCOA">Partially Constructed Object Access</BugCode> + </MessageCollection> \ No newline at end of file Index: findbugs.xml =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/etc/findbugs.xml,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- findbugs.xml 19 Sep 2005 04:20:19 -0000 1.14 +++ findbugs.xml 20 Sep 2005 02:28:42 -0000 1.15 @@ -54,6 +54,10 @@ speed="fast" reports="LSC_LITERAL_STRING_COMPARISON" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.PartiallyConstructedObjectAccess" + speed="fast" + reports="PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -66,5 +70,6 @@ <BugPattern abbrev="CE" type="CE_CLASS_ENVY" category="STYLE" experimental="true" /> <BugPattern abbrev="FP" type="FP_FINAL_PARAMETERS" category="STYLE" experimental="true" /> <BugPattern abbrev="LSC" type="LSC_LITERAL_STRING_COMPARISON" category="STYLE" experimental="true" /> + <BugPattern abbrev="PCOA" type="PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file |
From: Dave B. <dbr...@us...> - 2005-09-20 01:50:06
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22089/src/com/mebigfatguy/fbcontrib/detect Modified Files: DeclaredRuntimeException.java FinalParameters.java LiteralStringComparison.java Log Message: add copyrights Index: LiteralStringComparison.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LiteralStringComparison.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- LiteralStringComparison.java 19 Sep 2005 04:20:20 -0000 1.1 +++ LiteralStringComparison.java 20 Sep 2005 01:49:58 -0000 1.2 @@ -1,3 +1,21 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005 Dave Brosius + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ package com.mebigfatguy.fbcontrib.detect; import org.apache.bcel.classfile.Code; Index: DeclaredRuntimeException.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeclaredRuntimeException.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- DeclaredRuntimeException.java 16 Sep 2005 02:36:19 -0000 1.2 +++ DeclaredRuntimeException.java 20 Sep 2005 01:49:58 -0000 1.3 @@ -1,3 +1,21 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005 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; Index: FinalParameters.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FinalParameters.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- FinalParameters.java 19 Sep 2005 02:25:44 -0000 1.1 +++ FinalParameters.java 20 Sep 2005 01:49:58 -0000 1.2 @@ -1,3 +1,21 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005 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; |
From: Dave B. <dbr...@us...> - 2005-09-19 04:22:31
|
Update of /cvsroot/fb-contrib/fb-contrib/htdocs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14873/htdocs Modified Files: index.html Log Message: doc LSC Index: index.html =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/htdocs/index.html,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- index.html 19 Sep 2005 02:28:54 -0000 1.9 +++ index.html 19 Sep 2005 04:22:23 -0000 1.10 @@ -18,6 +18,10 @@ Detectors added in CVS<br/> Note: these detectors are still in testing<br/> <ul> + <li><b>Literal String Comparison</b><br/> + Finds methods that call the equals or compareTo methods on a String variable passing in a String literal. + A NullPointerException may occur if the string variable is null. If instead the method was called on + the string literal, and the variable was passed as an argument, this exception could never happen</li> <li><b>Final Parameters</b><br/> Finds parameters that are not written to, but are not defined as final. Doing so helps documents the method, and may help the jvm optimize the invocation of this method.</li> |
From: Dave B. <dbr...@us...> - 2005-09-19 04:20:29
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14551/src/com/mebigfatguy/fbcontrib/detect Added Files: LiteralStringComparison.java Log Message: Initial checkin: LSC Detector --- NEW FILE: LiteralStringComparison.java --- package com.mebigfatguy.fbcontrib.detect; import org.apache.bcel.classfile.Code; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.OpcodeStack; public class LiteralStringComparison extends BytecodeScanningDetector { private BugReporter bugReporter; private OpcodeStack stack; public LiteralStringComparison(BugReporter bugReporter) { this.bugReporter = bugReporter; stack = new OpcodeStack(); } public Object clone() throws CloneNotSupportedException { return super.clone(); } public void visitCode(Code obj) { stack.resetForMethodEntry(this); super.visitCode(obj); } public void sawOpcode(int seen) { try { if ((seen == INVOKEVIRTUAL) && "java/lang/String".equals(getClassConstantOperand())) { String calledMethodName = getNameConstantOperand(); String calledMethodSig = getSigConstantOperand(); if (("equals".equals(calledMethodName) && "(Ljava/lang/Object;)Z".equals(calledMethodSig)) || ("compareTo".equals(calledMethodName) && "(Ljava/lang/String;)I".equals(calledMethodSig))) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); Object constant = itm.getConstant(); if ((constant != null) && constant.getClass().equals(String.class)) { bugReporter.reportBug( new BugInstance( this, "LSC_LITERAL_STRING_COMPARISON", LOW_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(this)); } } } } } finally { stack.sawOpcode(this, seen); } } } |
From: Dave B. <dbr...@us...> - 2005-09-19 04:20:29
|
Update of /cvsroot/fb-contrib/fb-contrib/etc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14551/etc Modified Files: findbugs.xml messages.xml Log Message: Initial checkin: LSC Detector Index: messages.xml =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/etc/messages.xml,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- messages.xml 19 Sep 2005 02:25:44 -0000 1.12 +++ messages.xml 19 Sep 2005 04:20:20 -0000 1.13 @@ -122,6 +122,17 @@ ]]> </Details> </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.LiteralStringComparison"> + <Details> + <![CDATA[ + <p> Looks for methods that compare strings against literal strings, where the literal string + is passed as the parameter. If the .equals or .compareTo is called on the literal itself, passing + the variable as the parameter, you avoid the possibility of a NullPointerException.</p> + <p>It is a fast detector</p> + ]]> + </Details> + </Detector> <!-- BugPattern --> @@ -236,6 +247,18 @@ </Details> </BugPattern> + <BugPattern type="LSC_LITERAL_STRING_COMPARISON"> + <ShortDescription>method makes literal string comparisons passing the literal as an argument</ShortDescription> + <LongDescription>method {1} makes literal string comparisons passing the literal as an argument</LongDescription> + <Details> + <![CDATA[ + <p>This method calls the equals or compareTo methods on a String variable passing in a String literal. + A NullPointerException may occur if the string variable is null. If instead the method was called on + the string literal, and the variable was passed as an argument, this exception could never happen.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -247,5 +270,6 @@ <BugCode abbrev="DRE">Declared Runtime Exception</BugCode> <BugCode abbrev="CE">Class Envy</BugCode> <BugCode abbrev="FP">Final Parameters</BugCode> + <BugCode abbrev="LSC">Literal String Comparison</BugCode> </MessageCollection> \ No newline at end of file Index: findbugs.xml =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/etc/findbugs.xml,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- findbugs.xml 19 Sep 2005 02:25:44 -0000 1.13 +++ findbugs.xml 19 Sep 2005 04:20:19 -0000 1.14 @@ -50,7 +50,11 @@ speed="fast" reports="FP_FINAL_PARAMETERS" /> - <!-- BugPattern --> + <Detector class="com.mebigfatguy.fbcontrib.detect.LiteralStringComparison" + speed="fast" + reports="LSC_LITERAL_STRING_COMPARISON" /> + + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> <BugPattern abbrev="SCI" type="SCI_SYNCHRONIZED_COLLECTION_ITERATORS" category="CORRECTNESS" /> @@ -61,5 +65,6 @@ <BugPattern abbrev="DRE" type="DRE_DECLARED_RUNTIME_EXCEPTION" category="STYLE" /> <BugPattern abbrev="CE" type="CE_CLASS_ENVY" category="STYLE" experimental="true" /> <BugPattern abbrev="FP" type="FP_FINAL_PARAMETERS" category="STYLE" experimental="true" /> + <BugPattern abbrev="LSC" type="LSC_LITERAL_STRING_COMPARISON" category="STYLE" experimental="true" /> </FindbugsPlugin> \ No newline at end of file |
From: Dave B. <dbr...@us...> - 2005-09-19 04:20:29
|
Update of /cvsroot/fb-contrib/fb-contrib/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14551/samples Added Files: LSC_Sample.java Log Message: Initial checkin: LSC Detector --- NEW FILE: LSC_Sample.java --- public class LSC_Sample { public boolean test1(String s) { return s.equals("Hello"); } public boolean test2(String s) { return "Hello".equals(s); } public boolean test3(String s1, String s2) { return s1.equals(s2); } public int test4(String s) { return s.compareTo("Hello"); } public int test5(String s) { return "Hello".compareTo(s); } } |
From: Dave B. <dbr...@us...> - 2005-09-19 02:29:02
|
Update of /cvsroot/fb-contrib/fb-contrib/htdocs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29553/htdocs Modified Files: index.html Log Message: document fp Index: index.html =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/htdocs/index.html,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- index.html 16 Sep 2005 05:12:35 -0000 1.8 +++ index.html 19 Sep 2005 02:28:54 -0000 1.9 @@ -15,6 +15,14 @@ <a href="http://www.sourceforge.net/projects/fb-contrib">Project Page</a> <hr/> + Detectors added in CVS<br/> + Note: these detectors are still in testing<br/> + <ul> + <li><b>Final Parameters</b><br/> + Finds parameters that are not written to, but are not defined as final. Doing so helps + documents the method, and may help the jvm optimize the invocation of this method.</li> + </ul> + <hr/> Detectors added in v1.0.0<br/> <ul> <li><b>Overly Concrete Parameters</b><br/> |
From: Dave B. <dbr...@us...> - 2005-09-19 02:25:57
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28921/src/com/mebigfatguy/fbcontrib/detect Added Files: FinalParameters.java Log Message: Initial Checkin: FinalParameters --- NEW FILE: FinalParameters.java --- package com.mebigfatguy.fbcontrib.detect; import java.util.HashSet; import java.util.Set; import org.apache.bcel.Constants; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.LocalVariable; import org.apache.bcel.classfile.LocalVariableTable; import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.StatelessDetector; public class FinalParameters extends BytecodeScanningDetector implements StatelessDetector { private BugReporter bugReporter; private Set<Integer> changedParms; private int parmCount; private boolean isStatic; private boolean isAbstract; public FinalParameters(BugReporter bugReporter) { this.bugReporter = bugReporter; } public Object clone() throws CloneNotSupportedException { return super.clone(); } public void visitMethod(Method obj) { isStatic = (obj.getAccessFlags() & Constants.ACC_STATIC) != 0; isAbstract = (obj.getAccessFlags() & Constants.ACC_ABSTRACT) != 0; parmCount = Type.getArgumentTypes(obj.getSignature()).length; super.visitMethod(obj); } public void visitCode(Code obj) { if (isAbstract) return; changedParms = new HashSet<Integer>(); super.visitCode(obj); for (int i = 0; i < parmCount; i++) { if (changedParms.remove(new Integer(i))) continue; int reg; if (!isStatic) reg = i + 1; else reg = i; String parmName = getRegisterName(obj, reg); bugReporter.reportBug( new BugInstance( this, "FP_FINAL_PARAMETERS", LOW_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(this, 0) .addString(parmName)); } } public void sawOpcode(int seen) { if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { int parm = getAStoreParameter(seen); if (parm >= 0) changedParms.add(new Integer(parm)); } } private String getRegisterName(Code obj, int reg) { LocalVariableTable lvt = obj.getLocalVariableTable(); if (lvt != null) { LocalVariable lv = lvt.getLocalVariable(reg, 0); if (lv != null) return lv.getName(); } return String.valueOf(reg); } private int getAStoreParameter(int seen) { int reg; if (seen == ASTORE) reg = getRegisterOperand(); else reg = seen - ASTORE_0; if (!isStatic) reg--; if (reg >= parmCount) reg = -1; return reg; } } |
From: Dave B. <dbr...@us...> - 2005-09-19 02:25:57
|
Update of /cvsroot/fb-contrib/fb-contrib/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28921/samples Added Files: FP_Sample.java Log Message: Initial Checkin: FinalParameters --- NEW FILE: FP_Sample.java --- public abstract class FP_Sample { public void test1(String a) { System.out.println(a); } public void test2(String a) { a = "hello"; System.out.println(a); } public abstract void test3(String c); public String test4(String a, String b, String c) { a = c; if (a.equals(b)) b = a; return a + b + c; } } |
From: Dave B. <dbr...@us...> - 2005-09-19 02:25:57
|
Update of /cvsroot/fb-contrib/fb-contrib/etc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28921/etc Modified Files: findbugs.xml messages.xml Log Message: Initial Checkin: FinalParameters Index: messages.xml =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/etc/messages.xml,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- messages.xml 17 Sep 2005 20:48:31 -0000 1.11 +++ messages.xml 19 Sep 2005 02:25:44 -0000 1.12 @@ -112,7 +112,18 @@ </Details> </Detector> - <!-- BugPattern --> + <Detector class="com.mebigfatguy.fbcontrib.detect.FinalParameters"> + <Details> + <![CDATA[ + <p> Looks for methods that do not write to parameters, but do not declare these parameters final. + Doing so helps document the behaviour of the method, and may help the jvm to optimize the method + call.</p> + <p>It is a fast detector</p> + ]]> + </Details> + </Detector> + + <!-- BugPattern --> <BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING"> <ShortDescription>method passes simple concatenating string in StringBuffer or StringBuilder append</ShortDescription> @@ -213,6 +224,18 @@ </Details> </BugPattern> + <BugPattern type="FP_FINAL_PARAMETERS"> + <ShortDescription>method does not define a parameter as final, but could</ShortDescription> + <LongDescription>method {1} does not define a parameter as final, but could</LongDescription> + <Details> + <![CDATA[ + <p>This method correctly does not write to a parameter. To help document this, and to perhaps + help the jvm optimize the invocation of this method, you should consider defining these parameters + as final.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -223,5 +246,6 @@ <BugCode abbrev="UCC">Unrelated Collection Contents</BugCode> <BugCode abbrev="DRE">Declared Runtime Exception</BugCode> <BugCode abbrev="CE">Class Envy</BugCode> + <BugCode abbrev="FP">Final Parameters</BugCode> </MessageCollection> \ No newline at end of file Index: findbugs.xml =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/etc/findbugs.xml,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- findbugs.xml 17 Sep 2005 04:48:04 -0000 1.12 +++ findbugs.xml 19 Sep 2005 02:25:44 -0000 1.13 @@ -46,6 +46,10 @@ reports="CE_CLASS_ENVY" hidden="true"/> + <Detector class="com.mebigfatguy.fbcontrib.detect.FinalParameters" + speed="fast" + reports="FP_FINAL_PARAMETERS" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -56,5 +60,6 @@ <BugPattern abbrev="UCC" type="UCC_UNRELATED_COLLECTION_CONTENTS" category="STYLE" /> <BugPattern abbrev="DRE" type="DRE_DECLARED_RUNTIME_EXCEPTION" category="STYLE" /> <BugPattern abbrev="CE" type="CE_CLASS_ENVY" category="STYLE" experimental="true" /> + <BugPattern abbrev="FP" type="FP_FINAL_PARAMETERS" category="STYLE" experimental="true" /> </FindbugsPlugin> \ No newline at end of file |
From: Dave B. <dbr...@us...> - 2005-09-17 20:48:40
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30146/src/com/mebigfatguy/fbcontrib/detect Modified Files: ClassEnvy.java Log Message: count field access for envy. up percentage to .90, fix finding the called method signature. Index: ClassEnvy.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ClassEnvy.java 17 Sep 2005 04:44:50 -0000 1.2 +++ ClassEnvy.java 17 Sep 2005 20:48:31 -0000 1.3 @@ -22,6 +22,7 @@ import java.util.Iterator; import java.util.Map; +import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.generic.Type; @@ -41,9 +42,9 @@ private OpcodeStack stack; private String packageName; private String clsName; - private Map<String, Integer> clsMethodCount; - private int thisClsMethodCount; - private double envyPercent = 0.80; + private Map<String, Integer> clsAccessCount; + private int thisClsAccessCount; + private double envyPercent = 0.90; public ClassEnvy(BugReporter bugReporter) { this.bugReporter = bugReporter; @@ -71,21 +72,23 @@ public void visitCode(Code obj) { stack.resetForMethodEntry(this); - clsMethodCount = new HashMap<String, Integer>(); - thisClsMethodCount = 0; + clsAccessCount = new HashMap<String, Integer>(); + thisClsAccessCount = 0; super.visitCode(obj); String bestEnvy = null; - double bestPercent = -1.0; - Iterator<Map.Entry<String,Integer>> it = clsMethodCount.entrySet().iterator(); + double bestPercent = envyPercent; + Iterator<Map.Entry<String,Integer>> it = clsAccessCount.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String,Integer> entry = it.next(); + if (generalPurpose(entry.getKey())) + continue; Integer mc = entry.getValue(); if (mc.intValue() < 3) continue; - double percent = ((double)mc.intValue()) / ((double)(mc.intValue() + thisClsMethodCount)); + double percent = ((double)mc.intValue()) / ((double)(mc.intValue() + thisClsAccessCount)); if (percent > bestPercent) { bestPercent = percent; bestEnvy = entry.getKey(); @@ -112,40 +115,95 @@ return; if (seen == INVOKEINTERFACE) { - int parmCount = Type.getArgumentTypes(this.getMethodSig()).length; - try { - if (stack.getStackDepth() > parmCount) { - OpcodeStack.Item itm = stack.getStackItem(parmCount); - JavaClass jcls = itm.getJavaClass(); - if (jcls != null) - calledClass = itm.getJavaClass().getClassName(); - } - } catch (ClassNotFoundException cnfe) { - bugReporter.reportMissingClass(cnfe); - } - } - - String calledPackage = getPackageName(calledClass); - - if (calledClass.equals(clsName)) - thisClsMethodCount++; - else { - if (similarPackages(calledPackage, packageName, 2)) { - Integer cnt = clsMethodCount.get(calledClass); - if (cnt == null) { - cnt = new Integer(1); - clsMethodCount.put(calledClass, cnt); - } else { - clsMethodCount.put(calledClass, new Integer(cnt.intValue() + 1)); - } - } + int parmCount = Type.getArgumentTypes(this.getSigConstantOperand()).length; + if (!countClassAccess(parmCount)) + countClassAccess(calledClass); + } else { + countClassAccess(calledClass); } + } else if (seen == PUTFIELD) { + countClassAccess(1); + } else if (seen == GETFIELD) { + countClassAccess(0); } } finally { stack.sawOpcode(this, seen); } } + private boolean countClassAccess(int classAtStackIndex) { + String calledClass = null; + + try { + if (stack.getStackDepth() > classAtStackIndex) { + OpcodeStack.Item itm = stack.getStackItem(classAtStackIndex); + JavaClass cls = itm.getJavaClass(); + if (cls != null) + calledClass = cls.getClassName(); + else + return false; + } else + return false; + } catch (ClassNotFoundException cfne) { + bugReporter.reportMissingClass(cfne); + return false; + } + + countClassAccess(calledClass); + return true; + } + + private void countClassAccess(String calledClass) { + if (calledClass.equals(clsName)) + thisClsAccessCount++; + else { + String calledPackage = getPackageName(calledClass); + if (similarPackages(calledPackage, packageName, 2)) { + Integer cnt = clsAccessCount.get(calledClass); + if (cnt == null) { + cnt = new Integer(1); + clsAccessCount.put(calledClass, cnt); + } else { + clsAccessCount.put(calledClass, new Integer(cnt.intValue() + 1)); + } + } + } + } + + private boolean generalPurpose(String className) { + try { + JavaClass cls = Repository.lookupClass(className); + JavaClass[] infs = cls.getAllInterfaces(); + for (JavaClass inf : infs) { + String infName = inf.getClassName(); + if ("java.io.Serializable".equals(infName) + || "java.lang.Cloneable".equals(infName) + || "java.lang.Comparable".equals(infName) + || "java.lang.Runnable".equals(infName)) + continue; + if (infName.startsWith("java.lang.") + || infName.startsWith("javax.lang.")) + return true; + } + JavaClass[] sups = cls.getSuperClasses(); + for (JavaClass sup : sups) { + String supName = sup.getClassName(); + if ("java.lang.Object".equals(supName) + || "java.lang.Exception".equals(supName) + || "java.lang.RuntimeException".equals(supName) + || "java.lang.Throwable".equals(supName)) + continue; + if (supName.startsWith("java.lang.") + || supName.startsWith("javax.lang.")) + return true; + } + } catch (ClassNotFoundException cfne) { + bugReporter.reportMissingClass(cfne); + return true; + } + return false; + } + private String getPackageName(String className) { int dotPos = className.lastIndexOf("."); if (dotPos < 0) |
From: Dave B. <dbr...@us...> - 2005-09-17 20:48:40
|
Update of /cvsroot/fb-contrib/fb-contrib/etc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30146/etc Modified Files: messages.xml Log Message: count field access for envy. up percentage to .90, fix finding the called method signature. Index: messages.xml =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/etc/messages.xml,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- messages.xml 17 Sep 2005 04:42:35 -0000 1.10 +++ messages.xml 17 Sep 2005 20:48:31 -0000 1.11 @@ -104,7 +104,8 @@ <Details> <![CDATA[ <p> Looks for methods that use a high percentage of methods from another class over it's own - methods. When this is the case, it is often to implement this method in that other class. + methods. When this is the case, it is often better to implement this method in that other class, + by refactoring the class to accept parameters it needs from the source class. The reporting percentage can be set with system property 'fb-contrib.ce.percent'.</p> <p>It is a fast detector</p> ]]> @@ -206,8 +207,8 @@ <![CDATA[ <p>This method makes extensive use of methods from another class over methods of it's own class. Typically this means that the functionality that is accomplished by this method - most likely belongs with the class that is being used so liberally. Consider moving this - method to that class.</p> + most likely belongs with the class that is being used so liberally. Consider refactoring this + method to be contained in that class, and to accept all the parameters needed in the method signature.</p> ]]> </Details> </BugPattern> |
From: Dave B. <dbr...@us...> - 2005-09-17 04:48:12
|
Update of /cvsroot/fb-contrib/fb-contrib/etc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9472/etc Modified Files: findbugs.xml Log Message: hide class envy for now Index: findbugs.xml =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/etc/findbugs.xml,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- findbugs.xml 17 Sep 2005 04:42:35 -0000 1.11 +++ findbugs.xml 17 Sep 2005 04:48:04 -0000 1.12 @@ -43,7 +43,8 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.ClassEnvy" speed="fast" - reports="CE_CLASS_ENVY" /> + reports="CE_CLASS_ENVY" + hidden="true"/> <!-- BugPattern --> |
From: Dave B. <dbr...@us...> - 2005-09-17 04:44:58
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9033/src/com/mebigfatguy/fbcontrib/detect Modified Files: ClassEnvy.java Log Message: add copyright Index: ClassEnvy.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ClassEnvy.java 17 Sep 2005 04:42:35 -0000 1.1 +++ ClassEnvy.java 17 Sep 2005 04:44:50 -0000 1.2 @@ -1,3 +1,21 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005 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; |