fb-contrib-commit Mailing List for fb-contrib (Page 30)
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...> - 2009-02-28 03:22:13
|
Revision: 1116 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1116&view=rev Author: dbrosius Date: 2009-02-28 02:03:17 +0000 (Sat, 28 Feb 2009) Log Message: ----------- add FP test case from 2646424 Modified Paths: -------------- trunk/fb-contrib/samples/EXS_Sample.java Modified: trunk/fb-contrib/samples/EXS_Sample.java =================================================================== --- trunk/fb-contrib/samples/EXS_Sample.java 2009-02-27 13:57:20 UTC (rev 1115) +++ trunk/fb-contrib/samples/EXS_Sample.java 2009-02-28 02:03:17 UTC (rev 1116) @@ -56,6 +56,27 @@ throw new RuntimeException("Ooops"); } } + + public static void testFPBug2646424(String[] args) + { + if (args.length == 0) + { + try + { + Class.forName("java.lang.Integer"); + } + catch (ClassNotFoundException e) + { + e.printStackTrace(); + return; + } + } + else + { + throw new IllegalArgumentException("cannot take arguments"); + //EXS + } + } } class Super This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-27 13:57:30
|
Revision: 1115 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1115&view=rev Author: dbrosius Date: 2009-02-27 13:57:20 +0000 (Fri, 27 Feb 2009) Log Message: ----------- typo Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2009-02-27 13:56:49 UTC (rev 1114) +++ trunk/fb-contrib/etc/messages.xml 2009-02-27 13:57:20 UTC (rev 1115) @@ -916,7 +916,7 @@ <p>In addition, using a set, or keySet of a map, infers that you will be looking for items based on the value of a collection, which seems dubious at best.</p> <p>Finally, as collections are often modified, This may cause problems if the collection is modified, - thus changing hashCodes, etc, while the collection is in the set</p> + thus changing hashCodes, etc, while the collection is in the set.</p> <p>If you wish to keep a collection of collections, the outer collection should probably be a list to avoid these problems</p> <p>It is a moderately fast detector</p> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-27 13:57:01
|
Revision: 1114 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1114&view=rev Author: dbrosius Date: 2009-02-27 13:56:49 +0000 (Fri, 27 Feb 2009) Log Message: ----------- document DSOC Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2009-02-27 09:02:29 UTC (rev 1113) +++ trunk/fb-contrib/htdocs/index.html 2009-02-27 13:56:49 UTC (rev 1114) @@ -52,6 +52,16 @@ Detectors added in svn<br/> <div id="svn" style="display:block;"> <ul> + <li><b>[DSOC] Dubious Set of Collections</b><br/> + Looks for sets or keySets of maps that contain other collections. As typically collections calculate + their hashCode, equals and compareTo methods by iterating the collection and evaluating the same function + on each item in the collection, this can be costly from a performance point of view. + In addition, using a set, or keySet of a map, infers that you will be looking for items based on + the value of a collection, which seems dubious at best. + Finally, as collections are often modified, This may cause problems if the collection is modified, + thus changing hashCodes, etc, while the collection is in the set. + If you wish to keep a collection of collections, the outer collection should probably be a list + to avoid these problems</li> <li><b>[IICU] Incorrect Internal Class Use</b><br/> Looks for classes that use objects from internal sun, xerces or xalan packages. As these are internal to the respective products and subject to change or removal, these should not be used.</li> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-27 09:02:35
|
Revision: 1113 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1113&view=rev Author: dbrosius Date: 2009-02-27 09:02:29 +0000 (Fri, 27 Feb 2009) Log Message: ----------- add org/apache/xalan/extensions as external Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java 2009-02-27 08:40:19 UTC (rev 1112) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java 2009-02-27 09:02:29 UTC (rev 1113) @@ -45,6 +45,7 @@ internalPackages.add("org/apache/xalan/"); externalPackages.add("org/apache/xerces/xni/"); externalPackages.add("org/apache/xerces/xs/"); + externalPackages.add("org/apache/xalan/extensions"); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-27 08:40:25
|
Revision: 1112 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1112&view=rev Author: dbrosius Date: 2009-02-27 08:40:19 +0000 (Fri, 27 Feb 2009) Log Message: ----------- typo Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java 2009-02-27 08:14:46 UTC (rev 1111) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java 2009-02-27 08:40:19 UTC (rev 1112) @@ -29,7 +29,7 @@ import edu.umd.cs.findbugs.ba.ClassContext; /** - * looks for uses of sets of keySets of maps that contain other collections. As collection + * looks for uses of sets or keySets of maps that contain other collections. As collection * typically implement hashCode, equals and compareTo by iterating the contents of the collection * this can be costly from a performance point of view. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-27 08:14:55
|
Revision: 1111 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1111&view=rev Author: dbrosius Date: 2009-02-27 08:14:46 +0000 (Fri, 27 Feb 2009) Log Message: ----------- add fp Modified Paths: -------------- trunk/fb-contrib/samples/DSOC_Sample.java Modified: trunk/fb-contrib/samples/DSOC_Sample.java =================================================================== --- trunk/fb-contrib/samples/DSOC_Sample.java 2009-02-27 08:14:30 UTC (rev 1110) +++ trunk/fb-contrib/samples/DSOC_Sample.java 2009-02-27 08:14:46 UTC (rev 1111) @@ -20,4 +20,11 @@ m.put(s, "Foo"); } + + public void testFPListOfSets() { + Set<String> s = new HashSet<String>(); + List<Set<String>> l = new ArrayList<Set<String>>(); + + l.add(s); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-27 08:14:32
|
Revision: 1110 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1110&view=rev Author: dbrosius Date: 2009-02-27 08:14:30 +0000 (Fri, 27 Feb 2009) Log Message: ----------- typo Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java 2009-02-27 07:21:03 UTC (rev 1109) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java 2009-02-27 08:14:30 UTC (rev 1110) @@ -102,7 +102,7 @@ String signature = getSigConstantOperand(); if ("add".equals(methodName) - || "(Ljava/lang/Object;)Z".equals(signature) + && "(Ljava/lang/Object;)Z".equals(signature) && isImplementationOf(clsName, setCls)) { if (stack.getStackDepth() > 1) { OpcodeStack.Item item = stack.getStackItem(0); @@ -115,8 +115,8 @@ } } } else if ("put".equals(methodName) - || "(Ljava/lang/Object;LJava/lang/Object;)Ljava/lang/Object;".equals(signature) - && isImplementationOf(clsName, setCls)) { + && "(Ljava/lang/Object;LJava/lang/Object;)Ljava/lang/Object;".equals(signature) + && isImplementationOf(clsName, setCls)) { if (stack.getStackDepth() > 2) { OpcodeStack.Item item = stack.getStackItem(1); JavaClass entryCls = item.getJavaClass(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-27 07:21:15
|
Revision: 1109 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1109&view=rev Author: dbrosius Date: 2009-02-27 07:21:03 +0000 (Fri, 27 Feb 2009) Log Message: ----------- new DSOC detector Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2009-02-27 07:19:59 UTC (rev 1108) +++ trunk/fb-contrib/etc/findbugs.xml 2009-02-27 07:21:03 UTC (rev 1109) @@ -328,6 +328,10 @@ speed="fast" reports="IICU_INCORRECT_INTERNAL_CLASS_USE" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.DubiousSetOfCollections" + speed="moderate" + reports="DSOC_DUBIOUS_SET_OF_COLLECTIONS" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -441,4 +445,5 @@ <BugPattern abbrev="SCSS" type="SCSS_SUSPICIOUS_CLUSTERED_SESSION_SUPPORT" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="LO" type="LO_SUSPECT_LOG_CLASS" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="IICU" type="IICU_INCORRECT_INTERNAL_CLASS_USE" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="DSOC" type="DSOC_DUBIOUS_SET_OF_COLLECTIONS" category="PERFORMANCE" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2009-02-27 07:19:59 UTC (rev 1108) +++ trunk/fb-contrib/etc/messages.xml 2009-02-27 07:21:03 UTC (rev 1109) @@ -902,10 +902,28 @@ <li>org.apache.xerces.xxx</li> <li>org.apache.xalan.xxx</li> </ul> + <p>It is a fast detector</p> ]]> </Details> </Detector> + <Detector class="com.mebigfatguy.fbcontrib.detect.DubiousSetOfCollections"> + <Details> + <![CDATA[ + <p>looks for sets or keySets of maps that contain other collections. As typically collections calculate + their hashCode, equals and compareTo methods by iterating the collection and evaluating the same function + on each item in the collection, this can be costly from a performance point of view.</p> + <p>In addition, using a set, or keySet of a map, infers that you will be looking for items based on + the value of a collection, which seems dubious at best.</p> + <p>Finally, as collections are often modified, This may cause problems if the collection is modified, + thus changing hashCodes, etc, while the collection is in the set</p> + <p>If you wish to keep a collection of collections, the outer collection should probably be a list + to avoid these problems</p> + <p>It is a moderately fast detector</p> + ]]> + </Details> + </Detector> + <!-- BugPattern --> <BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING"> @@ -2370,6 +2388,25 @@ </Details> </BugPattern> + <BugPattern type="DSOC_DUBIOUS_SET_OF_COLLECTIONS"> + <ShortDescription>method uses a set of collections</ShortDescription> + <LongDescription>method {1} uses a set of collections</LongDescription> + <Details> + <![CDATA[ + <p>This method creates a set that contains other collections, or a Map who's keySet is + another collection. As collections tend to calculate hashCode, equals and compareTo by + iterating the contents of the collection, this can perform poorly.</p> + <p>In addition, when a set is used, you typically are using it to do contains, or find + type functionality, which seems dubious when do so on a collection</p> + <p>Finally, As a collection is often modified, problems will occur if the collection is + contained in a set, because the hashCode, equals or compareTo values will change while the + collection is in the set</p> + <p>If you wish to maintain a collection of collections, it is probably better to use a List + as the outer collection</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -2446,4 +2483,5 @@ <BugCode abbrev="SCSS">Suspicious Clustered Session Support</BugCode> <BugCode abbrev="LO">Logger Oddities</BugCode> <BugCode abbrev="IICU">Incorrect Internal Class use</BugCode> + <BugCode abbrev="DSOC">Dubious Set of Collections</BugCode> </MessageCollection> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-27 07:20:11
|
Revision: 1108 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1108&view=rev Author: dbrosius Date: 2009-02-27 07:19:59 +0000 (Fri, 27 Feb 2009) Log Message: ----------- new DSOC detector Added Paths: ----------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java 2009-02-27 07:19:59 UTC (rev 1108) @@ -0,0 +1,181 @@ +/* + * fb-contrib - Auxiliary detectors for Java programs + * Copyright (C) 2005-2009 Dave Brosius + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package com.mebigfatguy.fbcontrib.detect; + +import org.apache.bcel.Repository; +import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.JavaClass; + +import edu.umd.cs.findbugs.BugInstance; +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.OpcodeStack; +import edu.umd.cs.findbugs.ba.ClassContext; + +/** + * looks for uses of sets of keySets of maps that contain other collections. As collection + * typically implement hashCode, equals and compareTo by iterating the contents of the collection + * this can be costly from a performance point of view. + */ +public class DubiousSetOfCollections extends BytecodeScanningDetector { + + private static JavaClass collectionCls; + private static JavaClass setCls; + private static JavaClass mapCls; + static { + try { + collectionCls = Repository.lookupClass("java/util/Collection"); + setCls = Repository.lookupClass("java/util/Set"); + mapCls = Repository.lookupClass("java/util/Map"); + } catch (ClassNotFoundException cnfe) { + } + } + + private final BugReporter bugReporter; + private OpcodeStack stack; + + /** + * constructs a DSOC detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ + public DubiousSetOfCollections(final BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** + * implement the visitor to set up the opcode stack, and make sure that + * collection, set and map classes could be loaded. + * + * @param clsContext the context object of the currently parsed class + */ + @Override + public void visitClassContext(ClassContext clsContext) { + try { + if ((collectionCls == null) || (setCls == null) || (mapCls == null)) + return; + + stack = new OpcodeStack(); + super.visitClassContext(clsContext); + } finally { + stack = null; + } + } + + /** + * implements the visitor to reset the opcode stack + * + * @param code the context object of the currently parsed code block + */ + @Override + public void visitCode(Code code) { + stack.resetForMethodEntry(this); + super.visitCode(code); + } + /** + * implements the visitor look for adds to sets or puts to maps where the element + * to be added is a collection. + * + * @param seen the opcode of the currently parsed instruction + */ + @Override + public void sawOpcode(int seen) { + try { + if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE)) { + String clsName = getClassConstantOperand(); + String methodName = getNameConstantOperand(); + String signature = getSigConstantOperand(); + + if ("add".equals(methodName) + || "(Ljava/lang/Object;)Z".equals(signature) + && isImplementationOf(clsName, setCls)) { + if (stack.getStackDepth() > 1) { + OpcodeStack.Item item = stack.getStackItem(0); + JavaClass entryCls = item.getJavaClass(); + if (isImplementationOf(entryCls, collectionCls)) { + bugReporter.reportBug(new BugInstance(this, "DSOC_DUBIOUS_SET_OF_COLLECTIONS", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } else if ("put".equals(methodName) + || "(Ljava/lang/Object;LJava/lang/Object;)Ljava/lang/Object;".equals(signature) + && isImplementationOf(clsName, setCls)) { + if (stack.getStackDepth() > 2) { + OpcodeStack.Item item = stack.getStackItem(1); + JavaClass entryCls = item.getJavaClass(); + if (isImplementationOf(entryCls, collectionCls)) { + bugReporter.reportBug(new BugInstance(this, "DSOC_DUBIOUS_SET_OF_COLLECTIONS", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } finally { + stack.sawOpcode(this, seen); + } + } + + /** + * returns whether the class implements the interface + * + * @param clsName the name of the class + * @param inf the interface to check + * @return if the class implements the interface + */ + private boolean isImplementationOf(String clsName, JavaClass inf) { + + try { + if (clsName.startsWith("java/lang/")) + return false; + + JavaClass cls = Repository.lookupClass(clsName); + return isImplementationOf(cls, inf); + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } + return false; + } + + /** + * returns whether the class implements the interface + * + * @param cls the class + * @param inf the interface to check + * @return if the class implements the interface + */ + private boolean isImplementationOf(JavaClass cls, JavaClass inf) { + try { + if (cls == null) { + return false; + } + if (cls.implementationOf(inf)) { + return true; + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } + return false; + } + + +} Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-27 07:19:55
|
Revision: 1107 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1107&view=rev Author: dbrosius Date: 2009-02-27 07:19:46 +0000 (Fri, 27 Feb 2009) Log Message: ----------- new DSOC detector Added Paths: ----------- trunk/fb-contrib/samples/DSOC_Sample.java Added: trunk/fb-contrib/samples/DSOC_Sample.java =================================================================== --- trunk/fb-contrib/samples/DSOC_Sample.java (rev 0) +++ trunk/fb-contrib/samples/DSOC_Sample.java 2009-02-27 07:19:46 UTC (rev 1107) @@ -0,0 +1,23 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + + +public class DSOC_Sample { + public void testSetOfLists() + { + List<String> l = new ArrayList<String>(); + Set<List<String>> s = new HashSet<List<String>>(); + s.add(l); + } + + public void testKeySetOfSets() { + Set<String> s = new HashSet<String>(); + Map<Set<String>, String> m = new HashMap<Set<String>, String>(); + + m.put(s, "Foo"); + } +} Property changes on: trunk/fb-contrib/samples/DSOC_Sample.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-27 06:19:36
|
Revision: 1106 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1106&view=rev Author: dbrosius Date: 2009-02-27 06:19:31 +0000 (Fri, 27 Feb 2009) Log Message: ----------- add xalan Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java 2009-02-27 06:19:14 UTC (rev 1105) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java 2009-02-27 06:19:31 UTC (rev 1106) @@ -42,6 +42,7 @@ static { internalPackages.add("com/sun/"); internalPackages.add("org/apache/xerces/"); + internalPackages.add("org/apache/xalan/"); externalPackages.add("org/apache/xerces/xni/"); externalPackages.add("org/apache/xerces/xs/"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-27 06:19:19
|
Revision: 1105 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1105&view=rev Author: dbrosius Date: 2009-02-27 06:19:14 +0000 (Fri, 27 Feb 2009) Log Message: ----------- add xalan to IICU Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2009-02-27 06:12:26 UTC (rev 1104) +++ trunk/fb-contrib/etc/messages.xml 2009-02-27 06:19:14 UTC (rev 1105) @@ -900,6 +900,7 @@ <ul> <li>com.sun.xxx</li> <li>org.apache.xerces.xxx</li> + <li>org.apache.xalan.xxx</li> </ul> ]]> </Details> @@ -2363,6 +2364,7 @@ <ul> <li>com.sun.xxx</li> <li>org.apache.xerces.xxx</li> + <li>org.apache.xalan.xxx</li> </ul> ]]> </Details> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-27 06:12:36
|
Revision: 1104 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1104&view=rev Author: dbrosius Date: 2009-02-27 06:12:26 +0000 (Fri, 27 Feb 2009) Log Message: ----------- better fixups Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2009-02-22 07:26:14 UTC (rev 1103) +++ trunk/fb-contrib/htdocs/index.html 2009-02-27 06:12:26 UTC (rev 1104) @@ -53,8 +53,8 @@ <div id="svn" style="display:block;"> <ul> <li><b>[IICU] Incorrect Internal Class Use</b><br/> - Looks for classes that use objects from com.sun.xxx packages. As these are internal - to sun and subject to change or removal, these should not be used.</li> + Looks for classes that use objects from internal sun, xerces or xalan packages. As these are internal + to the respective products and subject to change or removal, these should not be used.</li> <li><b>[LO] Logger Oddities</b><br/> Looks for uses of log4j or slf4j where the class specified when creating the logger is not the same as the class in which this logger is used.</li> @@ -186,7 +186,7 @@ Looks for if/else blocks where a series of them use instanceof on the same variable to determine what to do. If these classes are related by inheritance, this often is better handled through calling a single overridden method.</li> - <li><b>[RMC] Redundant Method Calls</b><br/> + <li><b>[PRMC] Possibly Redundant Method Calls</b><br/> Looks for calls of the same method on the same object when that object hasn't changed. This often is redundant, and the second call can be removed, or combined.</li> <li><b>[UTA] Use toArray</b><br/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-22 07:26:17
|
Revision: 1103 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1103&view=rev Author: dbrosius Date: 2009-02-22 07:26:14 +0000 (Sun, 22 Feb 2009) Log Message: ----------- use isEmpty Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PartiallyConstructedObjectAccess.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.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/UnrelatedReturnValues.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2009-02-22 07:19:47 UTC (rev 1102) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2009-02-22 07:26:14 UTC (rev 1103) @@ -38,7 +38,7 @@ * return or exception thrown from the try block, and masks it. */ public class AbnormalFinallyBlockReturn extends BytecodeScanningDetector { - private BugReporter bugReporter; + private final BugReporter bugReporter; private List<FinallyBlockInfo> fbInfo; private int loadedReg; @@ -93,7 +93,7 @@ } } - if (fbInfo.size() > 0) + if (!fbInfo.isEmpty()) super.visitCode(obj); } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java 2009-02-22 07:19:47 UTC (rev 1102) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java 2009-02-22 07:26:14 UTC (rev 1103) @@ -141,7 +141,7 @@ @Override public void sawOpcode(int seen) { - if (possibleParmRegs.size() == 0) + if (possibleParmRegs.isEmpty()) return; try { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2009-02-22 07:19:47 UTC (rev 1102) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2009-02-22 07:26:14 UTC (rev 1103) @@ -55,7 +55,7 @@ */ public class FieldCouldBeLocal extends BytecodeScanningDetector { - private BugReporter bugReporter; + private final BugReporter bugReporter; private ClassContext clsContext; private Map<String, FieldInfo> localizableFields; private CFG cfg; @@ -120,7 +120,7 @@ */ @Override public void visitMethod(Method obj) { - if (localizableFields.size() == 0) + if (localizableFields.isEmpty()) return; String methodName = obj.getName(); @@ -202,8 +202,8 @@ LinkedList<BlockState> toBeProcessed = new LinkedList<BlockState>(); toBeProcessed.add(new BlockState(bb, uncheckedFields)); - while (toBeProcessed.size() > 0) { - if (localizableFields.size() == 0) + while (!toBeProcessed.isEmpty()) { + if (localizableFields.isEmpty()) return; BlockState bState = toBeProcessed.removeFirst(); bb = bState.getBasicBlock(); @@ -221,7 +221,7 @@ if (ins instanceof GETFIELD) { localizableFields.remove(fieldName); - if (localizableFields.size() == 0) + if (localizableFields.isEmpty()) return; } else { FieldInfo finfo = localizableFields.get(fieldName); @@ -248,7 +248,7 @@ * holds information about a field and it's first usage */ private static class FieldInfo { - private FieldAnnotation fieldAnnotation; + private final FieldAnnotation fieldAnnotation; private SourceLineAnnotation srcLineAnnotation; /** @@ -290,8 +290,8 @@ * holds the parse state of the current basic block, and what fields are left to be checked */ private static class BlockState { - private BasicBlock basicBlock; - private Set<String> uncheckedFields; + private final BasicBlock basicBlock; + private final Set<String> uncheckedFields; /** * creates a BlockState consisting of the next basic block to parse, Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2009-02-22 07:19:47 UTC (rev 1102) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2009-02-22 07:26:14 UTC (rev 1103) @@ -53,7 +53,7 @@ */ public class OverlyConcreteParameter extends BytecodeScanningDetector { - private BugReporter bugReporter; + private final BugReporter bugReporter; private JavaClass[] constrainingClasses; private Map<Integer, Map<JavaClass, List<MethodInfo>>> parameterDefiners; private Set<Integer> usedParameters; @@ -158,7 +158,7 @@ @Override public void sawOpcode(final int seen) { - if (parameterDefiners.size() == 0) + if (parameterDefiners.isEmpty()) return; try { @@ -375,7 +375,7 @@ if (!methodDefined) it.remove(); } - if (definers.size() == 0) { + if (definers.isEmpty()) { parameterDefiners.remove(Integer14.valueOf(reg)); } } @@ -440,7 +440,7 @@ it.remove(); } - if (definers.size() == 0) + if (definers.isEmpty()) parameterDefiners.remove(Integer14.valueOf(reg)); } } @@ -448,9 +448,9 @@ public static class MethodInfo { - private String methodName; - private String methodSig; - private String[] methodExceptions; + private final String methodName; + private final String methodSig; + private final String[] methodExceptions; public MethodInfo(String name, String sig, String[] excs) { methodName = name; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PartiallyConstructedObjectAccess.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PartiallyConstructedObjectAccess.java 2009-02-22 07:19:47 UTC (rev 1102) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PartiallyConstructedObjectAccess.java 2009-02-22 07:26:14 UTC (rev 1103) @@ -45,7 +45,7 @@ */ public class PartiallyConstructedObjectAccess extends BytecodeScanningDetector { - private BugReporter bugReporter; + private final BugReporter bugReporter; private OpcodeStack stack; private Map<Method, Map<Method, SourceLineAnnotation>> methodToCalledMethods; private boolean reportedCtor; @@ -95,7 +95,7 @@ reportedCtor = false; super.visitCode(obj); - if (reportedCtor || (methodToCalledMethods.get(m).size() == 0)) + if (reportedCtor || (methodToCalledMethods.get(m).isEmpty())) methodToCalledMethods.remove(getMethod()); } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java 2009-02-22 07:19:47 UTC (rev 1102) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java 2009-02-22 07:26:14 UTC (rev 1103) @@ -93,7 +93,7 @@ increasingMethods.add("insertElementAt"); increasingMethods.add("put"); } - private BugReporter bugReporter; + private final BugReporter bugReporter; private Map<XField, SourceLineAnnotation> bloatableFields; private OpcodeStack stack; private String methodName; @@ -185,7 +185,7 @@ try { stack.mergeJumps(this); - if (bloatableFields.size() == 0) + if (bloatableFields.isEmpty()) return; if ((seen == INVOKEVIRTUAL) Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java 2009-02-22 07:19:47 UTC (rev 1102) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java 2009-02-22 07:26:14 UTC (rev 1103) @@ -37,7 +37,7 @@ */ public class SpoiledChildInterfaceImplementor implements Detector { - private BugReporter bugReporter; + private final BugReporter bugReporter; /** * constructs a SCII detector given the reporter to report bugs on @@ -131,7 +131,7 @@ */ private void filterSuperInterfaceMethods(JavaClass inf, Set<String> infMethods, JavaClass cls) { try { - if (infMethods.size() == 0) + if (infMethods.isEmpty()) return; JavaClass[] superInfs = inf.getInterfaces(); @@ -139,7 +139,7 @@ if (cls.implementationOf(superInf)) { Set<String> superInfMethods = buildMethodSet(superInf); infMethods.removeAll(superInfMethods); - if (infMethods.size() == 0) + if (infMethods.isEmpty()) return; } filterSuperInterfaceMethods(superInf, infMethods, cls); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java 2009-02-22 07:19:47 UTC (rev 1102) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java 2009-02-22 07:26:14 UTC (rev 1103) @@ -44,7 +44,7 @@ */ public class SyncCollectionIterators extends BytecodeScanningDetector { - private BugReporter bugReporter; + private final BugReporter bugReporter; private static Set<String> synchCollectionNames = new HashSet<String>(); static { synchCollectionNames.add("synchronizedSet"); @@ -168,7 +168,7 @@ } } else if (calledClass.startsWith("java/util/")) { if ("iterator".equals(getNameConstantOperand())) { - if (monitorObjects.size() == 0) { + if (monitorObjects.isEmpty()) { bugReporter.reportBug( new BugInstance( this, "SCI_SYNCHRONIZED_COLLECTION_ITERATORS", NORMAL_PRIORITY) .addClass(this) .addMethod(this) Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java 2009-02-22 07:19:47 UTC (rev 1102) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java 2009-02-22 07:26:14 UTC (rev 1103) @@ -57,7 +57,7 @@ COLLECTION_CLASSES.add("java/util/SortedMap"); COLLECTION_CLASSES.add("java/util/SortedSet"); } - private BugReporter bugReporter; + private final BugReporter bugReporter; private OpcodeStack stack; private Map<String, Set<String>> memberCollections; private Map<Integer, Set<String>> localCollections; @@ -207,18 +207,18 @@ private void mergeItem(final Set<String> supers, final Set<SourceLineAnnotation> sla, final OpcodeStack.Item addItm) throws ClassNotFoundException { - if (supers.size() == 0) + if (supers.isEmpty()) return; Set<String> s = new HashSet<String>(); addNewItem(s, addItm); - if (s.size() == 0) + if (s.isEmpty()) return; intersection(supers, s); - if (supers.size() == 0) { + if (supers.isEmpty()) { BugInstance bug = new BugInstance(this, "UCC_UNRELATED_COLLECTION_CONTENTS", NORMAL_PRIORITY) .addClass(this); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java 2009-02-22 07:19:47 UTC (rev 1102) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java 2009-02-22 07:26:14 UTC (rev 1103) @@ -44,7 +44,7 @@ */ public class UnrelatedReturnValues extends BytecodeScanningDetector { - private BugReporter bugReporter; + private final BugReporter bugReporter; private OpcodeStack stack; private JavaClass currentClass; private Map<JavaClass, Integer> returnTypes; @@ -190,7 +190,7 @@ } } - if (possibleCommonTypes.size() == 0) + if (possibleCommonTypes.isEmpty()) return null; for (JavaClass cls : possibleCommonTypes) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-22 07:19:50
|
Revision: 1102 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1102&view=rev Author: dbrosius Date: 2009-02-22 07:19:47 +0000 (Sun, 22 Feb 2009) Log Message: ----------- fix stutter 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 2009-02-22 03:48:02 UTC (rev 1101) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2009-02-22 07:19:47 UTC (rev 1102) @@ -258,8 +258,8 @@ int pc = getPC(); int[] offsets = getSwitchOffsets(); List<Integer> targets = new ArrayList<Integer>(); - for (int i = 0; i < offsets.length; i++) - targets.add(Integer14.valueOf(offsets[i] + pc)); + for (int offset : offsets) + targets.add(Integer14.valueOf(offset + pc)); Integer defOffset = Integer14.valueOf(getDefaultSwitchOffset() + pc); if (!targets.contains(defOffset)) targets.add(defOffset); @@ -273,7 +273,7 @@ lastTarget = nextTarget; } switchTargets.addAll(targets); - } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEVIRTUAL)) { + } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE)) { 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...> - 2009-02-22 03:48:07
|
Revision: 1101 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1101&view=rev Author: dbrosius Date: 2009-02-22 03:48:02 +0000 (Sun, 22 Feb 2009) Log Message: ----------- CLI ignores array access from strings arrays returned from String.split Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java 2009-02-22 03:20:25 UTC (rev 1100) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java 2009-02-22 03:48:02 UTC (rev 1101) @@ -31,7 +31,9 @@ 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; +import edu.umd.cs.findbugs.ba.XMethod; /** * looks for methods that access arrays or classes that implement java.util.List @@ -45,11 +47,17 @@ private static final int SEEN_NOTHING = 0; private static final int SEEN_CONSTANT_0 = 1; private static final int SEEN_CONSTANT = 2; + private static final Set<String> ubiquitousMethods = new HashSet<String>(); + static { + ubiquitousMethods.add("java.lang.String.split(Ljava/lang/String;)[Ljava/lang/String;"); + } - private BugReporter bugReporter; + + private final BugReporter bugReporter; private int state; private Set<Integer> iConst0Looped; - private int max_iConst0LoopDistance; + private final int max_iConst0LoopDistance; + private OpcodeStack stack; /** * constructs a CLI detector given the reporter to report bugs on @@ -69,9 +77,11 @@ public void visitClassContext(ClassContext classContext) { try { iConst0Looped = new HashSet<Integer>(); + stack = new OpcodeStack(); super.visitClassContext(classContext); } finally { iConst0Looped = null; + stack = null; } } @@ -84,6 +94,7 @@ public void visitMethod(Method obj) { state = SEEN_NOTHING; iConst0Looped.clear(); + stack.resetForMethodEntry(this); } /** @@ -93,79 +104,104 @@ */ @Override public void sawOpcode(int seen) { - - switch (state) { - case SEEN_NOTHING: - if (seen == ICONST_0) - state = SEEN_CONSTANT_0; - else if ((seen >= ICONST_1) && (seen <= ICONST_5)) - state = SEEN_CONSTANT; - else if ((seen == LDC) || (seen == LDC_W)) { - Constant c = getConstantRefOperand(); - if (c instanceof ConstantInteger) + try { + switch (state) { + case SEEN_NOTHING: + if (seen == ICONST_0) + state = SEEN_CONSTANT_0; + else if ((seen >= ICONST_1) && (seen <= ICONST_5)) state = SEEN_CONSTANT; - } - break; - - case SEEN_CONSTANT_0: - case SEEN_CONSTANT: - switch (seen) { - case AALOAD: - if ("main".equals(this.getMethodName())) - break; - //FALL THRU - case IALOAD: - case LALOAD: - case FALOAD: - case DALOAD: - //case BALOAD: byte and char indexing seems prevalent, and - //case CALOAD: usually harmless so ignore - case SALOAD: - if (state == SEEN_CONSTANT_0) - iConst0Looped.add(Integer14.valueOf(getPC())); - else { - bugReporter.reportBug(new BugInstance(this, "CLI_CONSTANT_LIST_INDEX", NORMAL_PRIORITY) + else if ((seen == LDC) || (seen == LDC_W)) { + Constant c = getConstantRefOperand(); + if (c instanceof ConstantInteger) + state = SEEN_CONSTANT; + } + break; + + case SEEN_CONSTANT_0: + case SEEN_CONSTANT: + switch (seen) { + case AALOAD: + if ("main".equals(this.getMethodName())) + break; + //FALL THRU + case IALOAD: + case LALOAD: + case FALOAD: + case DALOAD: + //case BALOAD: byte and char indexing seems prevalent, and + //case CALOAD: usually harmless so ignore + case SALOAD: + if (state == SEEN_CONSTANT_0) + iConst0Looped.add(Integer14.valueOf(getPC())); + else { + if (stack.getStackDepth() > 1) { + OpcodeStack.Item item = stack.getStackItem(1); + if (!isArrayFromUbiquitousMethod(item)) { + bugReporter.reportBug(new BugInstance(this, "CLI_CONSTANT_LIST_INDEX", NORMAL_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(this)); - } - break; - - case INVOKEVIRTUAL: - if ("java/util/List".equals(getClassConstantOperand())) { - String methodName = getNameConstantOperand(); - if ("get".equals(methodName)) { - if (state == SEEN_CONSTANT_0) - iConst0Looped.add(Integer14.valueOf(getPC())); - else { - bugReporter.reportBug(new BugInstance(this, "CLI_CONSTANT_LIST_INDEX", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + } } + } + break; + + case INVOKEVIRTUAL: + if ("java/util/List".equals(getClassConstantOperand())) { + String methodName = getNameConstantOperand(); + if ("get".equals(methodName)) { + if (state == SEEN_CONSTANT_0) + iConst0Looped.add(Integer14.valueOf(getPC())); + else { + bugReporter.reportBug(new BugInstance(this, "CLI_CONSTANT_LIST_INDEX", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + break; + } + state = SEEN_NOTHING; + break; + } + + if (((seen >= IFEQ) && (seen <= GOTO)) || (seen == GOTO_W)) { + int branchTarget = this.getBranchTarget(); + Iterator<Integer> it = iConst0Looped.iterator(); + while (it.hasNext()) { + int bugPC = it.next().intValue(); + if (branchTarget < bugPC) { + if ((bugPC - branchTarget) < max_iConst0LoopDistance) { + bugReporter.reportBug(new BugInstance(this, "CLI_CONSTANT_LIST_INDEX", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this, bugPC)); } - break; - } - state = SEEN_NOTHING; - break; - } - - if (((seen >= IFEQ) && (seen <= GOTO)) || (seen == GOTO_W)) { - int branchTarget = this.getBranchTarget(); - Iterator<Integer> it = iConst0Looped.iterator(); - while (it.hasNext()) { - int bugPC = it.next().intValue(); - if (branchTarget < bugPC) { - if ((bugPC - branchTarget) < max_iConst0LoopDistance) { - bugReporter.reportBug(new BugInstance(this, "CLI_CONSTANT_LIST_INDEX", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this, bugPC)); + it.remove(); } - it.remove(); } } + } finally { + stack.sawOpcode(this, seen); } } + + /** + * returns whether the array item was returned from a common method that the user can't do anything about + * and so don't report CLI in this case. + * + * @param item the stack item representing the array + * @return if the array was returned from a common method + */ + private boolean isArrayFromUbiquitousMethod(OpcodeStack.Item item) { + XMethod method = item.getReturnValueOf(); + if (method == null) + return false; + + String methodDesc = method.getClassName() + '.' + method.getName() + method.getSignature(); + return ubiquitousMethods.contains(methodDesc); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-22 03:20:27
|
Revision: 1100 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1100&view=rev Author: dbrosius Date: 2009-02-22 03:20:25 +0000 (Sun, 22 Feb 2009) Log Message: ----------- add a test that really shouldn't be reported by CLI Modified Paths: -------------- trunk/fb-contrib/samples/CLI_Sample.java Modified: trunk/fb-contrib/samples/CLI_Sample.java =================================================================== --- trunk/fb-contrib/samples/CLI_Sample.java 2009-02-21 18:35:12 UTC (rev 1099) +++ trunk/fb-contrib/samples/CLI_Sample.java 2009-02-22 03:20:25 UTC (rev 1100) @@ -4,7 +4,7 @@ public String test1(String[] sa) { String result = ""; - for (int i = 0; i < sa.length; i++) + for (String element : sa) result += sa[0]; return result; } @@ -16,4 +16,12 @@ String ss = sa[2]; return name + address + ss; } + + public String testFPSplit(String s) { + String[] parts = s.split(","); + String a = parts[0]; + String b = parts[1]; + String c = parts[2]; + return c + b + a; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-21 18:35:18
|
Revision: 1099 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1099&view=rev Author: dbrosius Date: 2009-02-21 18:35:12 +0000 (Sat, 21 Feb 2009) Log Message: ----------- mark org/apache/xerces/xs/ as external Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java 2009-02-21 08:18:02 UTC (rev 1098) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java 2009-02-21 18:35:12 UTC (rev 1099) @@ -43,6 +43,7 @@ internalPackages.add("com/sun/"); internalPackages.add("org/apache/xerces/"); externalPackages.add("org/apache/xerces/xni/"); + externalPackages.add("org/apache/xerces/xs/"); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-21 08:18:12
|
Revision: 1098 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1098&view=rev Author: dbrosius Date: 2009-02-21 08:18:02 +0000 (Sat, 21 Feb 2009) Log Message: ----------- add org.apache.xerces to the list of internal packages Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2009-02-21 06:01:17 UTC (rev 1097) +++ trunk/fb-contrib/etc/messages.xml 2009-02-21 08:18:02 UTC (rev 1098) @@ -893,9 +893,14 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.IncorrectInternalClassUse"> <Details> <![CDATA[ - <p>looks for classes that rely on sun internal classes in the package com.sun.xxxx. As these classes - are not officially released from sun, they are subject to change or removal, and thus, + <p>looks for classes that rely on internal classes in the various apis or libraries. As these + classes are not officially released from the api vendor, they are subject to change or removal, and thus, should not be counted on.</p> + Packages that shouldn't be used are: + <ul> + <li>com.sun.xxx</li> + <li>org.apache.xerces.xxx</li> + </ul> ]]> </Details> </Detector> @@ -2347,13 +2352,18 @@ </BugPattern> <BugPattern type="IICU_INCORRECT_INTERNAL_CLASS_USE"> - <ShortDescription>class relies on internal sun classes</ShortDescription> - <LongDescription>class {0} relies on internal sun classes</LongDescription> + <ShortDescription>class relies on internal api classes</ShortDescription> + <LongDescription>class {0} relies on internal api classes</LongDescription> <Details> <![CDATA[ - <p>This class makes use of internal sun classes in the package com.sun.xxx. As these + <p>This class makes use of internal api classes. As these classes are not documented, nor externally released as part of the api, they are subject to change or removal. You should not be using these classes.</p> + Packages that shouldn't be used are: + <ul> + <li>com.sun.xxx</li> + <li>org.apache.xerces.xxx</li> + </ul> ]]> </Details> </BugPattern> Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java 2009-02-21 06:01:17 UTC (rev 1097) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java 2009-02-21 08:18:02 UTC (rev 1098) @@ -38,8 +38,11 @@ { private final BugReporter bugReporter; private static final Set<String> internalPackages = new HashSet<String>(); + private static final Set<String> externalPackages = new HashSet<String>(); static { internalPackages.add("com/sun/"); + internalPackages.add("org/apache/xerces/"); + externalPackages.add("org/apache/xerces/xni/"); } /** @@ -51,7 +54,7 @@ } /** - * implements the visitor to look for classes that reference com.sun.xxx classes + * implements the visitor to look for classes that reference com.sun.xxx, or org.apache.xerces.xxx classes * by looking for class constants in the constant pool * * @param classContext the context object of the currently parsed class @@ -88,11 +91,23 @@ * @returns whether the class is internal */ private boolean isInternal(String clsName) { + boolean internal = false; for (String internalPackage : internalPackages) { - if (clsName.startsWith(internalPackage)) - return true; + if (clsName.startsWith(internalPackage)) { + internal = true; + break; + } } - return false; + if (internal) { + for (String externalPackage : externalPackages) { + if (clsName.startsWith(externalPackage)) { + internal = false; + break; + } + } + } + + return internal; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-21 06:01:22
|
Revision: 1097 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1097&view=rev Author: dbrosius Date: 2009-02-21 06:01:17 +0000 (Sat, 21 Feb 2009) Log Message: ----------- rework to extend IICU to other libraries Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java 2009-02-20 07:10:32 UTC (rev 1096) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java 2009-02-21 06:01:17 UTC (rev 1097) @@ -17,6 +17,9 @@ * 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.Constant; import org.apache.bcel.classfile.ConstantClass; import org.apache.bcel.classfile.ConstantPool; @@ -34,6 +37,10 @@ public class IncorrectInternalClassUse implements Detector { private final BugReporter bugReporter; + private static final Set<String> internalPackages = new HashSet<String>(); + static { + internalPackages.add("com/sun/"); + } /** * constructs a IICU detector given the reporter to report bugs on @@ -51,14 +58,14 @@ */ public void visitClassContext(ClassContext context) { JavaClass cls = context.getJavaClass(); - if (!cls.getClassName().startsWith("com/sun/")) { + if (!isInternal(cls.getClassName())) { ConstantPool pool = cls.getConstantPool(); int numItems = pool.getLength(); for (int i = 0; i < numItems; i++) { Constant c = pool.getConstant(i); if (c instanceof ConstantClass) { String clsName = ((ConstantClass) c).getBytes(pool); - if (clsName.startsWith("com/sun/")) { + if (isInternal(clsName)) { bugReporter.reportBug(new BugInstance(this, "IICU_INCORRECT_INTERNAL_CLASS_USE", NORMAL_PRIORITY) .addClass(cls) .addString(clsName)); @@ -67,7 +74,25 @@ } } } - + + /** + * implementation stub for Detector interface + */ public void report() { } + + /** + * determines if the class in question is an internal class by looking at package prefixes + * + * @param clsName the name of the class to check + * @returns whether the class is internal + */ + private boolean isInternal(String clsName) { + for (String internalPackage : internalPackages) { + if (clsName.startsWith(internalPackage)) + return true; + } + + return false; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-20 07:10:38
|
Revision: 1096 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1096&view=rev Author: dbrosius Date: 2009-02-20 07:10:32 +0000 (Fri, 20 Feb 2009) Log Message: ----------- add static exception builders to the ignore set Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2009-02-20 07:07:12 UTC (rev 1095) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2009-02-20 07:10:32 UTC (rev 1096) @@ -222,7 +222,7 @@ } else if (isPossibleExBuilder(catchInfo.getRegister())) { markAsValid = true; } - } else if (seen == INVOKEINTERFACE) { + } else if ((seen == INVOKEINTERFACE) || (seen == INVOKESTATIC)) { if (isPossibleExBuilder(catchInfo.getRegister())) markAsValid = true; } else if (seen == ATHROW) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-20 07:07:17
|
Revision: 1095 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1095&view=rev Author: dbrosius Date: 2009-02-20 07:07:12 +0000 (Fri, 20 Feb 2009) Log Message: ----------- add another test Modified Paths: -------------- trunk/fb-contrib/samples/LEST_Sample.java Modified: trunk/fb-contrib/samples/LEST_Sample.java =================================================================== --- trunk/fb-contrib/samples/LEST_Sample.java 2009-02-20 05:24:36 UTC (rev 1094) +++ trunk/fb-contrib/samples/LEST_Sample.java 2009-02-20 07:07:12 UTC (rev 1095) @@ -82,11 +82,30 @@ } catch (NumberFormatException nfe) { - throw wrap(nfe); + Exception e = wrap(nfe); + throw e; } } + public void testLestFP5(String s) throws Exception + { + double d; + try + { + d = Double.parseDouble(s); + } + catch (NumberFormatException nfe) + { + Exception e = wrapStatic(nfe); + throw e; + } + } + private Exception wrap(Exception e) { return new Exception(e); } + + private static Exception wrapStatic(Exception e) { + return new Exception(e); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-20 05:24:40
|
Revision: 1094 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1094&view=rev Author: dbrosius Date: 2009-02-20 05:24:36 +0000 (Fri, 20 Feb 2009) Log Message: ----------- document IICU Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2009-02-20 05:22:46 UTC (rev 1093) +++ trunk/fb-contrib/htdocs/index.html 2009-02-20 05:24:36 UTC (rev 1094) @@ -52,6 +52,9 @@ Detectors added in svn<br/> <div id="svn" style="display:block;"> <ul> + <li><b>[IICU] Incorrect Internal Class Use</b><br/> + Looks for classes that use objects from com.sun.xxx packages. As these are internal + to sun and subject to change or removal, these should not be used.</li> <li><b>[LO] Logger Oddities</b><br/> Looks for uses of log4j or slf4j where the class specified when creating the logger is not the same as the class in which this logger is used.</li> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-20 05:22:51
|
Revision: 1093 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1093&view=rev Author: dbrosius Date: 2009-02-20 05:22:46 +0000 (Fri, 20 Feb 2009) Log Message: ----------- add detector IICU Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/IICU_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2009-02-16 01:04:37 UTC (rev 1092) +++ trunk/fb-contrib/etc/findbugs.xml 2009-02-20 05:22:46 UTC (rev 1093) @@ -324,6 +324,10 @@ speed="fast" reports="LO_SUSPECT_LOG_CLASS" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.IncorrectInternalClassUse" + speed="fast" + reports="IICU_INCORRECT_INTERNAL_CLASS_USE" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -436,4 +440,5 @@ <BugPattern abbrev="WEM" type="WEM_WEAK_EXCEPTION_MESSAGING" category="STYLE" /> <BugPattern abbrev="SCSS" type="SCSS_SUSPICIOUS_CLUSTERED_SESSION_SUPPORT" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="LO" type="LO_SUSPECT_LOG_CLASS" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="IICU" type="IICU_INCORRECT_INTERNAL_CLASS_USE" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2009-02-16 01:04:37 UTC (rev 1092) +++ trunk/fb-contrib/etc/messages.xml 2009-02-20 05:22:46 UTC (rev 1093) @@ -890,6 +890,16 @@ </Details> </Detector> + <Detector class="com.mebigfatguy.fbcontrib.detect.IncorrectInternalClassUse"> + <Details> + <![CDATA[ + <p>looks for classes that rely on sun internal classes in the package com.sun.xxxx. As these classes + are not officially released from sun, they are subject to change or removal, and thus, + should not be counted on.</p> + ]]> + </Details> + </Detector> + <!-- BugPattern --> <BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING"> @@ -2336,6 +2346,18 @@ </Details> </BugPattern> + <BugPattern type="IICU_INCORRECT_INTERNAL_CLASS_USE"> + <ShortDescription>class relies on internal sun classes</ShortDescription> + <LongDescription>class {0} relies on internal sun classes</LongDescription> + <Details> + <![CDATA[ + <p>This class makes use of internal sun classes in the package com.sun.xxx. As these + classes are not documented, nor externally released as part of the api, they are subject + to change or removal. You should not be using these classes.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -2411,4 +2433,5 @@ <BugCode abbrev="WEM">Weak Exception Messaging</BugCode> <BugCode abbrev="SCSS">Suspicious Clustered Session Support</BugCode> <BugCode abbrev="LO">Logger Oddities</BugCode> + <BugCode abbrev="IICU">Incorrect Internal Class use</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/IICU_Sample.java =================================================================== --- trunk/fb-contrib/samples/IICU_Sample.java (rev 0) +++ trunk/fb-contrib/samples/IICU_Sample.java 2009-02-20 05:22:46 UTC (rev 1093) @@ -0,0 +1,12 @@ +import javax.xml.datatype.XMLGregorianCalendar; + +import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl; + + +public class IICU_Sample +{ + public void test() + { + XMLGregorianCalendar cal = new XMLGregorianCalendarImpl(); + } +} Property changes on: trunk/fb-contrib/samples/IICU_Sample.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java 2009-02-20 05:22:46 UTC (rev 1093) @@ -0,0 +1,73 @@ +/* + * fb-contrib - Auxiliary detectors for Java programs + * Copyright (C) 2005-2009 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.Constant; +import org.apache.bcel.classfile.ConstantClass; +import org.apache.bcel.classfile.ConstantPool; +import org.apache.bcel.classfile.JavaClass; + +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 use objects from com.sun.xxx packages. As these are internal + * to sun and subject to change, this should not be done. + */ +public class IncorrectInternalClassUse implements Detector +{ + private final BugReporter bugReporter; + + /** + * constructs a IICU detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ + public IncorrectInternalClassUse(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** + * implements the visitor to look for classes that reference com.sun.xxx classes + * by looking for class constants in the constant pool + * + * @param classContext the context object of the currently parsed class + */ + public void visitClassContext(ClassContext context) { + JavaClass cls = context.getJavaClass(); + if (!cls.getClassName().startsWith("com/sun/")) { + ConstantPool pool = cls.getConstantPool(); + int numItems = pool.getLength(); + for (int i = 0; i < numItems; i++) { + Constant c = pool.getConstant(i); + if (c instanceof ConstantClass) { + String clsName = ((ConstantClass) c).getBytes(pool); + if (clsName.startsWith("com/sun/")) { + bugReporter.reportBug(new BugInstance(this, "IICU_INCORRECT_INTERNAL_CLASS_USE", NORMAL_PRIORITY) + .addClass(cls) + .addString(clsName)); + } + } + } + } + } + + public void report() { + } +} Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-02-16 01:04:41
|
Revision: 1092 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1092&view=rev Author: dbrosius Date: 2009-02-16 01:04:37 +0000 (Mon, 16 Feb 2009) Log Message: ----------- Fix LO problems due to variable name collision bug Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java 2009-02-14 16:51:59 UTC (rev 1091) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java 2009-02-16 01:04:37 UTC (rev 1092) @@ -31,7 +31,7 @@ import edu.umd.cs.findbugs.ba.ClassContext; public class LoggerOddities extends BytecodeScanningDetector { - private BugReporter bugReporter; + private final BugReporter bugReporter; private OpcodeStack stack; private String clsName; @@ -101,12 +101,12 @@ ldcClassName = ((ConstantUtf8)pool.getConstant(((ConstantClass) c).getNameIndex())).getBytes(); } } else if (seen == INVOKESTATIC) { - String clsName = getClassConstantOperand(); + String callingClsName = getClassConstantOperand(); String mthName = getNameConstantOperand(); String loggingClassName = null; - if ("org/slf4j/LoggerFactory".equals(clsName) + if ("org/slf4j/LoggerFactory".equals(callingClsName) && "getLogger".equals(mthName)) { String signature = getSigConstantOperand(); @@ -123,7 +123,7 @@ loggingClassName = loggingClassName.replace('.', '/'); } } - } else if ("org/apache/log4j/Logger".equals(clsName) + } else if ("org/apache/log4j/Logger".equals(callingClsName) && "getLogger".equals(mthName)) { String signature = getSigConstantOperand(); @@ -152,7 +152,7 @@ if (loggingClassName != null) { if (stack.getStackDepth() > 0) { if ((loggingClassName != null) && !loggingClassName.equals(clsName)) { - bugReporter.reportBug(new BugInstance(this, "LO_SUSPECT_LOG_CLASS", clsName.contains("$") ? LOW_PRIORITY : NORMAL_PRIORITY) + bugReporter.reportBug(new BugInstance(this, "LO_SUSPECT_LOG_CLASS", callingClsName.contains("$") ? LOW_PRIORITY : NORMAL_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(this)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |