fb-contrib-commit Mailing List for fb-contrib (Page 42)
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...> - 2007-02-01 09:38:23
|
Revision: 816 http://svn.sourceforge.net/fb-contrib/?rev=816&view=rev Author: dbrosius Date: 2007-02-01 01:38:22 -0800 (Thu, 01 Feb 2007) Log Message: ----------- getting closer Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2007-02-01 08:28:00 UTC (rev 815) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2007-02-01 09:38:22 UTC (rev 816) @@ -19,8 +19,8 @@ package com.mebigfatguy.fbcontrib.detect; import java.io.File; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; +import java.io.IOException; +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; @@ -35,6 +35,7 @@ import org.apache.bcel.Constants; import org.apache.bcel.classfile.ClassParser; import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; import com.mebigfatguy.fbcontrib.utils.Integer14; @@ -47,18 +48,20 @@ { private static final Map<Integer, String> verRegEx = new HashMap<Integer, String>(); static { - verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_1), "(jdk|jre)1.1"); - verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_2), "(jdk|jre)1.2"); - verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_3), "(jdk|jre)1.3"); - verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_4), "(jdk|jre)1.4"); - verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_5), "(jdk|jre)1.5"); - verRegEx.put(Integer14.valueOf(50), "jdk1.6"); + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_1), "(jdk|j2?re)1.1"); + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_2), "(jdk|j2?re)1.2"); + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_3), "(jdk|j2?re)1.3"); + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_4), "(jdk|j2?re)1.4"); + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_5), "(jdk|j2?re)1.5"); + verRegEx.put(Integer14.valueOf(50), "(jdk|j2?re)1.6"); } private static final Pattern jarPattern = Pattern.compile("jar:file:/*([^!]*)"); private Map<String, File> versionPaths; private Map<Integer, Map<String, Set<String>>> validMethodsByVersion; + private Map<String, String> superNames; private File jdksRoot = null; + JavaClass cls; private URLClassLoader jdkLoader; private Integer clsMajorVersion; private BugReporter bugReporter; @@ -67,25 +70,23 @@ this.bugReporter = bugReporter; versionPaths = new HashMap<String, File>(); validMethodsByVersion = new HashMap<Integer, Map<String, Set<String>>>(); + superNames = new HashMap<String, String>(); } - /* - * Use BCEL to load class, not URLClassLoader - * - * ClassParser parser = new ClassParser(is, className); - * JavaClass clazz = parser.parse(); - */ @Override public void visitClassContext(ClassContext classContext) { try { - JavaClass cls = classContext.getJavaClass(); + cls = classContext.getJavaClass(); clsMajorVersion = Integer14.valueOf(cls.getMajor()); File rtJar = getRTJarFile(cls); - jdkLoader = new URLClassLoader(new URL[] {rtJar.toURL()}); - super.visitClassContext(classContext); + if (rtJar != null) { + jdkLoader = new URLClassLoader(new URL[] {rtJar.toURL()}); + super.visitClassContext(classContext); + } } catch (MalformedURLException mue) { //Hmm, what to do } finally { + cls = null; jdkLoader = null; } } @@ -94,6 +95,8 @@ public void sawOpcode(int seen) { String clsName = null; + InputStream is = null; + try { if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE) @@ -107,42 +110,70 @@ validMethods = new HashMap<String, Set<String>>(); validMethodsByVersion.put(clsMajorVersion, validMethods); } - Set<String> methodInfos = validMethods.get(clsName); - if (methodInfos == null) { - Class c = jdkLoader.loadClass(clsName.replace('/', '.')); - Method[] methods = c.getDeclaredMethods(); - - methodInfos = new HashSet<String>(); - validMethods.put(clsName, methodInfos); - - for (Method m : methods) { - if ((m.getModifiers() & Modifier.PRIVATE) == 0) { - String[] mi = m.toString().split("\\(\\)"); - int dotPos = mi[0].lastIndexOf('.'); - String name = mi[0].substring(dotPos+1); - String sig; - if (mi.length == 1) - sig = "()"; - else { - if (mi[1].trim().startsWith("throws")) - sig = "()"; - else - sig = "(" + mi[1] + ")"; - } - methodInfos.add(name + sig); - } - } + + if (!isValid(validMethods, clsName)) { + bugReporter.reportBug(new BugInstance(this, "SJVU_SUSPICIOUS_JDK_VERSION_USE", HIGH_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); } + } + } + } catch (Exception e) { + // Hmm what to do + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException ioe) { + } + } + } + } + + private boolean isValid(Map<String, Set<String>> validMethods, String clsName) throws IOException, ClassNotFoundException { + InputStream is = null; + + try { + Set<String> methodInfos = validMethods.get(clsName); + if (methodInfos == null) { + is = jdkLoader.getResourceAsStream(clsName + ".class"); + if (is != null) { + ClassParser parser = new ClassParser(is, clsName); + JavaClass calledClass = parser.parse(); + superNames.put(clsName, calledClass.getSuperclassName().replace('.', '/')); + Method[] methods = calledClass.getMethods(); + methodInfos = new HashSet<String>(); + validMethods.put(clsName, methodInfos); + + for (Method m : methods) { + if (!m.isPrivate()) + methodInfos.add(m.getName() + m.getSignature()); + } + } + else { + return true; + } + } - } catch (ClassNotFoundException cnfe) { - if (clsName.startsWith("java/")) { - bugReporter.reportBug(new BugInstance(this, "SJVU_SUSPICIOUS_JDK_VERSION_USE", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + + String wantedMethod = getNameConstantOperand() + getSigConstantOperand(); + if (methodInfos.contains(wantedMethod)) + return true; + else if ("java/lang/Object".equals(clsName)) + return false; + else + return isValid(validMethods, superNames.get(clsName)); + } + finally { + if (is != null) { + try { + is.close(); + } catch (IOException ioe) { + } } } } @@ -175,25 +206,26 @@ return null; jdksRoot = new File(URLDecoder.decode(jdksRoot.getParentFile().getPath())); - - File[] possibleJdks = jdksRoot.listFiles(); - for (File possibleJdk : possibleJdks) { - m = verPat.matcher(possibleJdk.getName()); - if (m.find()) { - File wantedRtJar = new File(possibleJdk, "lib/rt.jar"); - if (!wantedRtJar.exists()) { - wantedRtJar = new File(possibleJdk, "jre/lib/rt.jar"); - if (!wantedRtJar.exists()) - return null; - } - versionPaths.put(versionStr, wantedRtJar); - return wantedRtJar; - } - } } } } + File[] possibleJdks = jdksRoot.listFiles(); + for (File possibleJdk : possibleJdks) { + Pattern verPat = Pattern.compile(versionStr); + Matcher m = verPat.matcher(possibleJdk.getName()); + if (m.find()) { + File wantedRtJar = new File(possibleJdk, "lib/rt.jar"); + if (!wantedRtJar.exists()) { + wantedRtJar = new File(possibleJdk, "jre/lib/rt.jar"); + if (!wantedRtJar.exists()) + return null; + } + versionPaths.put(versionStr, wantedRtJar); + return wantedRtJar; + } + } + return null; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-02-01 08:28:00
|
Revision: 815 http://svn.sourceforge.net/fb-contrib/?rev=815&view=rev Author: dbrosius Date: 2007-02-01 00:28:00 -0800 (Thu, 01 Feb 2007) Log Message: ----------- more updates - still miles away Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2007-02-01 08:15:34 UTC (rev 814) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2007-02-01 08:28:00 UTC (rev 815) @@ -33,6 +33,7 @@ import java.util.regex.Pattern; import org.apache.bcel.Constants; +import org.apache.bcel.classfile.ClassParser; import org.apache.bcel.classfile.JavaClass; import com.mebigfatguy.fbcontrib.utils.Integer14; @@ -68,6 +69,12 @@ validMethodsByVersion = new HashMap<Integer, Map<String, Set<String>>>(); } + /* + * Use BCEL to load class, not URLClassLoader + * + * ClassParser parser = new ClassParser(is, className); + * JavaClass clazz = parser.parse(); + */ @Override public void visitClassContext(ClassContext classContext) { try { @@ -110,10 +117,24 @@ for (Method m : methods) { if ((m.getModifiers() & Modifier.PRIVATE) == 0) { - methodInfos.add(m.toString()); + String[] mi = m.toString().split("\\(\\)"); + int dotPos = mi[0].lastIndexOf('.'); + String name = mi[0].substring(dotPos+1); + String sig; + if (mi.length == 1) + sig = "()"; + else { + if (mi[1].trim().startsWith("throws")) + sig = "()"; + else + sig = "(" + mi[1] + ")"; + } + methodInfos.add(name + sig); } } } + + } } } catch (ClassNotFoundException cnfe) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-02-01 08:15:34
|
Revision: 814 http://svn.sourceforge.net/fb-contrib/?rev=814&view=rev Author: dbrosius Date: 2007-02-01 00:15:34 -0800 (Thu, 01 Feb 2007) Log Message: ----------- made a copy Added Paths: ----------- tags/v3_2_1/ Copied: tags/v3_2_1 (from rev 813, trunk/fb-contrib) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-02-01 08:01:56
|
Revision: 813 http://svn.sourceforge.net/fb-contrib/?rev=813&view=rev Author: dbrosius Date: 2007-02-01 00:01:57 -0800 (Thu, 01 Feb 2007) Log Message: ----------- 1.4 compat 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 2007-02-01 08:01:15 UTC (rev 812) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2007-02-01 08:01:57 UTC (rev 813) @@ -424,7 +424,7 @@ if (stores == null) stores = new HashMap<Integer, Integer>(); - stores.put(Integer.valueOf(reg), Integer.valueOf(pc)); + stores.put(Integer14.valueOf(reg), Integer14.valueOf(pc)); } /** @@ -437,7 +437,7 @@ if (loads == null) loads = new HashMap<Integer, Integer>(); - loads.put(Integer.valueOf(reg), Integer.valueOf(pc)); + loads.put(Integer14.valueOf(reg), Integer14.valueOf(pc)); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-02-01 08:01:14
|
Revision: 812 http://svn.sourceforge.net/fb-contrib/?rev=812&view=rev Author: dbrosius Date: 2007-02-01 00:01:15 -0800 (Thu, 01 Feb 2007) Log Message: ----------- get ready for 3.2.1 Modified Paths: -------------- trunk/fb-contrib/build.xml Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2007-02-01 08:00:24 UTC (rev 811) +++ trunk/fb-contrib/build.xml 2007-02-01 08:01:15 UTC (rev 812) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.2.0"/> + <property name="fb-contrib.version" value="3.2.1"/> <target name="clean" description="removes all generated collateral"> <delete dir="${classes.dir}"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-02-01 08:00:26
|
Revision: 811 http://svn.sourceforge.net/fb-contrib/?rev=811&view=rev Author: dbrosius Date: 2007-02-01 00:00:24 -0800 (Thu, 01 Feb 2007) Log Message: ----------- Initial checkin - SJVU .. not even close Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/SJVU_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-02-01 07:58:41 UTC (rev 810) +++ trunk/fb-contrib/etc/findbugs.xml 2007-02-01 08:00:24 UTC (rev 811) @@ -275,7 +275,13 @@ speed="fast" reports="USS_USE_STRING_SPLIT" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousJDKVersionUse" + speed="slow" + reports="SJVU_SUSPICIOUS_JDK_VERSION_USE" + hidden="true" + disabled="true" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -356,4 +362,5 @@ <BugPattern abbrev="SCII" type="SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR" category="STYLE" experimental="true" /> <BugPattern abbrev="DWI" type="DWI_DELETING_WHILE_ITERATING" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="USS" type="USS_USE_STRING_SPLIT" category="STYLE" experimental="true" /> + <BugPattern abbrev="SJVU" type="SJVU_SUSPICIOUS_JDK_VERSION_USE" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-02-01 07:58:41 UTC (rev 810) +++ trunk/fb-contrib/etc/messages.xml 2007-02-01 08:00:24 UTC (rev 811) @@ -737,6 +737,13 @@ ]]> </Details> </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousJDKVersionUse"> + <Details> + <![CDATA[ + ]]> + </Details> + </Detector> <!-- BugPattern --> @@ -1763,6 +1770,15 @@ </Details> </BugPattern> + <BugPattern type="SJVU_SUSPICIOUS_JDK_VERSION_USE"> + <ShortDescription></ShortDescription> + <LongDescription></LongDescription> + <Details> + <![CDATA[ + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -1826,4 +1842,5 @@ <BugCode abbrev="SCII">Spoiled Child Interface Implementor</BugCode> <BugCode abbrev="DWI">Deleting While Iterating</BugCode> <BugCode abbrev="USS">Use String Split</BugCode> + <BugCode abbrev="SJVU">Suspicious JDK VersionUse</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/SJVU_Sample.java =================================================================== --- trunk/fb-contrib/samples/SJVU_Sample.java (rev 0) +++ trunk/fb-contrib/samples/SJVU_Sample.java 2007-02-01 08:00:24 UTC (rev 811) @@ -0,0 +1,8 @@ + +public class SJVU_Sample +{ + public void test14using15(int i) + { + Integer ii = Integer.valueOf(i); + } +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2007-02-01 08:00:24 UTC (rev 811) @@ -0,0 +1,178 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005-2007 Dave Brosius + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package com.mebigfatguy.fbcontrib.detect; + +import java.io.File; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.bcel.Constants; +import org.apache.bcel.classfile.JavaClass; + +import com.mebigfatguy.fbcontrib.utils.Integer14; + +import edu.umd.cs.findbugs.BugInstance; +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.ba.ClassContext; + +public class SuspiciousJDKVersionUse extends BytecodeScanningDetector +{ + private static final Map<Integer, String> verRegEx = new HashMap<Integer, String>(); + static { + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_1), "(jdk|jre)1.1"); + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_2), "(jdk|jre)1.2"); + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_3), "(jdk|jre)1.3"); + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_4), "(jdk|jre)1.4"); + verRegEx.put(Integer14.valueOf(Constants.MAJOR_1_5), "(jdk|jre)1.5"); + verRegEx.put(Integer14.valueOf(50), "jdk1.6"); + } + private static final Pattern jarPattern = Pattern.compile("jar:file:/*([^!]*)"); + + private Map<String, File> versionPaths; + private Map<Integer, Map<String, Set<String>>> validMethodsByVersion; + private File jdksRoot = null; + private URLClassLoader jdkLoader; + private Integer clsMajorVersion; + private BugReporter bugReporter; + + public SuspiciousJDKVersionUse(BugReporter bugReporter) { + this.bugReporter = bugReporter; + versionPaths = new HashMap<String, File>(); + validMethodsByVersion = new HashMap<Integer, Map<String, Set<String>>>(); + } + + @Override + public void visitClassContext(ClassContext classContext) { + try { + JavaClass cls = classContext.getJavaClass(); + clsMajorVersion = Integer14.valueOf(cls.getMajor()); + File rtJar = getRTJarFile(cls); + jdkLoader = new URLClassLoader(new URL[] {rtJar.toURL()}); + super.visitClassContext(classContext); + } catch (MalformedURLException mue) { + //Hmm, what to do + } finally { + jdkLoader = null; + } + } + + @Override + public void sawOpcode(int seen) { + + String clsName = null; + try { + if ((seen == INVOKEVIRTUAL) + || (seen == INVOKEINTERFACE) + || (seen == INVOKESTATIC) + || (seen == INVOKESPECIAL)) { + clsName = getClassConstantOperand(); + if ((clsName.startsWith("java/")) + || (clsName.startsWith("javax/"))) { + Map<String, Set<String>> validMethods = validMethodsByVersion.get(clsMajorVersion); + if (validMethods == null) { + validMethods = new HashMap<String, Set<String>>(); + validMethodsByVersion.put(clsMajorVersion, validMethods); + } + Set<String> methodInfos = validMethods.get(clsName); + if (methodInfos == null) { + Class c = jdkLoader.loadClass(clsName.replace('/', '.')); + Method[] methods = c.getDeclaredMethods(); + + methodInfos = new HashSet<String>(); + validMethods.put(clsName, methodInfos); + + for (Method m : methods) { + if ((m.getModifiers() & Modifier.PRIVATE) == 0) { + methodInfos.add(m.toString()); + } + } + } + } + } + } catch (ClassNotFoundException cnfe) { + if (clsName.startsWith("java/")) { + bugReporter.reportBug(new BugInstance(this, "SJVU_SUSPICIOUS_JDK_VERSION_USE", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + + private File getRTJarFile(JavaClass cls) { + String versionStr = verRegEx.get(clsMajorVersion); + if (versionStr == null) + return null; + + File rtPath = versionPaths.get(versionStr); + if (rtPath != null) + return rtPath; + + if (jdksRoot == null) { + URL jdkUrl = SuspiciousJDKVersionUse.class.getResource("/java/lang/Object.class"); + if (jdkUrl != null) { + Matcher m = jarPattern.matcher(jdkUrl.toExternalForm()); + + if (m.find()) { + String path = m.group(1); + jdksRoot = new File(path); + Pattern verPat = Pattern.compile(versionStr); + m = verPat.matcher(jdksRoot.getName()); + while ((jdksRoot.getParentFile() != null) && !m.find()) { + jdksRoot = jdksRoot.getParentFile(); + m = verPat.matcher(jdksRoot.getName()); + } + + if (jdksRoot.getParentFile() == null) + return null; + + jdksRoot = new File(URLDecoder.decode(jdksRoot.getParentFile().getPath())); + + File[] possibleJdks = jdksRoot.listFiles(); + for (File possibleJdk : possibleJdks) { + m = verPat.matcher(possibleJdk.getName()); + if (m.find()) { + File wantedRtJar = new File(possibleJdk, "lib/rt.jar"); + if (!wantedRtJar.exists()) { + wantedRtJar = new File(possibleJdk, "jre/lib/rt.jar"); + if (!wantedRtJar.exists()) + return null; + } + versionPaths.put(versionStr, wantedRtJar); + return wantedRtJar; + } + } + } + } + } + + return null; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-02-01 07:58:42
|
Revision: 810 http://svn.sourceforge.net/fb-contrib/?rev=810&view=rev Author: dbrosius Date: 2007-01-31 23:58:41 -0800 (Wed, 31 Jan 2007) Log Message: ----------- make 1.4 compatible Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2007-01-31 03:45:16 UTC (rev 809) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2007-02-01 07:58:41 UTC (rev 810) @@ -94,11 +94,11 @@ ignoreRegs.clear(); Method method = getMethod(); if (!method.isStatic()) - ignoreRegs.add(Integer.valueOf(0)); + ignoreRegs.add(Integer14.valueOf(0)); int[] parmRegs = RegisterUtils.getParameterRegisters(method); for (int parm : parmRegs) { - ignoreRegs.add(Integer.valueOf(parm)); + ignoreRegs.add(Integer14.valueOf(parm)); } rootScopeBlock = new ScopeBlock(0, obj.getLength()); @@ -106,7 +106,7 @@ CodeException[] exceptions = obj.getExceptionTable(); if (exceptions != null) { for (CodeException ex : exceptions) { - catchHandlers.add(Integer.valueOf(ex.getHandlerPC())); + catchHandlers.add(Integer14.valueOf(ex.getHandlerPC())); } } @@ -143,7 +143,7 @@ || ((seen >= FSTORE_0) && (seen <= FSTORE_1)) || ((seen >= DSTORE_0) && (seen <= DSTORE_1))) { int reg = RegisterUtils.getStoreReg(this, seen); - Integer iReg = Integer.valueOf(reg); + Integer iReg = Integer14.valueOf(reg); int pc = getPC(); if (catchHandlers.contains(Integer14.valueOf(pc))) ignoreRegs.add(iReg); @@ -171,18 +171,18 @@ || ((seen >= FLOAD_0) && (seen <= FLOAD_1)) || ((seen >= DLOAD_0) && (seen <= DLOAD_1))) { int reg = RegisterUtils.getLoadReg(this, seen); - if (!ignoreRegs.contains(Integer.valueOf(reg))) { + if (!ignoreRegs.contains(Integer14.valueOf(reg))) { ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC()); if (sb != null) sb.addLoad(reg, getPC()); else - ignoreRegs.add(Integer.valueOf(reg)); + ignoreRegs.add(Integer14.valueOf(reg)); } } else if (((seen >= IFEQ) && (seen <= GOTO)) || (seen == GOTO_W)) { int target = getBranchTarget(); if (target > getPC()) { if ((seen == GOTO) || (seen == GOTO_W)) { - Integer nextPC = Integer.valueOf(getNextPC()); + Integer nextPC = Integer14.valueOf(getNextPC()); if (!switchTargets.contains(nextPC)) { ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), getNextPC()); if (sb == null) { @@ -226,8 +226,8 @@ int[] offsets = getSwitchOffsets(); List<Integer> targets = new ArrayList<Integer>(); for (int i = 0; i < offsets.length; i++) - targets.add(Integer.valueOf(offsets[i] + pc)); - Integer defOffset = Integer.valueOf(getDefaultSwitchOffset() + pc); + targets.add(Integer14.valueOf(offsets[i] + pc)); + Integer defOffset = Integer14.valueOf(getDefaultSwitchOffset() + pc); if (!targets.contains(defOffset)) targets.add(defOffset); Collections.sort(targets); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-01-31 03:45:16 UTC (rev 809) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-02-01 07:58:41 UTC (rev 810) @@ -24,6 +24,7 @@ import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.JavaClass; +import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; @@ -103,7 +104,7 @@ if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { int reg = RegisterUtils.getALoadReg(this, seen); - Integer type = regValueType.get(Integer.valueOf(reg)); + Integer type = regValueType.get(Integer14.valueOf(reg)); if (type != null) state = type.intValue(); else @@ -114,14 +115,14 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); int reg = RegisterUtils.getAStoreReg(this, seen); - regValueType.put(Integer.valueOf(reg), (Integer)item.getUserValue()); + regValueType.put(Integer14.valueOf(reg), (Integer)item.getUserValue()); } state = SEEN_NOTHING; return; } if ((seen == ILOAD) || ((seen >= ILOAD_0) && (seen <= ILOAD_3))) { int reg = RegisterUtils.getLoadReg(this, seen); - Integer type = regValueType.get(Integer.valueOf(reg)); + Integer type = regValueType.get(Integer14.valueOf(reg)); if (type != null) state = type.intValue(); else @@ -132,7 +133,7 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); int reg = RegisterUtils.getStoreReg(this, seen); - regValueType.put(Integer.valueOf(reg), (Integer)item.getUserValue()); + regValueType.put(Integer14.valueOf(reg), (Integer)item.getUserValue()); } state = SEEN_NOTHING; return; @@ -226,7 +227,7 @@ if (state != SEEN_NOTHING) { if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); - item.setUserValue(Integer.valueOf(state)); + item.setUserValue(Integer14.valueOf(state)); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-31 03:45:16
|
Revision: 809 http://svn.sourceforge.net/fb-contrib/?rev=809&view=rev Author: dbrosius Date: 2007-01-30 19:45:16 -0800 (Tue, 30 Jan 2007) Log Message: ----------- made a copy Added Paths: ----------- tags/v3_2_0/ Copied: tags/v3_2_0 (from rev 808, trunk/fb-contrib) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-31 03:29:34
|
Revision: 808 http://svn.sourceforge.net/fb-contrib/?rev=808&view=rev Author: dbrosius Date: 2007-01-30 19:29:33 -0800 (Tue, 30 Jan 2007) Log Message: ----------- get ready for 3.2.0 Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/FBContrib.java Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2007-01-31 03:28:10 UTC (rev 807) +++ trunk/fb-contrib/build.xml 2007-01-31 03:29:33 UTC (rev 808) @@ -142,7 +142,7 @@ destdir="${javadoc.dir}" windowtitle="fb-contrib api"> <doctitle><![CDATA[<h1>fb-contrib javadoc</h1>]]></doctitle> - <bottom><![CDATA[<i>Copyright © 2005-2006 MeBigFatGuy.com. All Rights Reserved.</i>]]></bottom> + <bottom><![CDATA[<i>Copyright © 2005-2007 MeBigFatGuy.com. All Rights Reserved.</i>]]></bottom> </javadoc> </target> </project> \ No newline at end of file Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/FBContrib.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/FBContrib.java 2007-01-31 03:28:10 UTC (rev 807) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/FBContrib.java 2007-01-31 03:29:33 UTC (rev 808) @@ -28,7 +28,7 @@ * @param args standard command line args */ public static void main(final String[] args) { - JOptionPane.showMessageDialog( null, "To use fb-contrib, copy this jar file into your local FindBugs plugin directory, and use FindBugs as usual.\n\nfb-contrib is a trademark of MeBigFatGuy.com\nFindBugs is a trademark of the University of Maryland", "fb-contrib: copyright 2005-2006", JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showMessageDialog( null, "To use fb-contrib, copy this jar file into your local FindBugs plugin directory, and use FindBugs as usual.\n\nfb-contrib is a trademark of MeBigFatGuy.com\nFindBugs is a trademark of the University of Maryland", "fb-contrib: copyright 2005-2007", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-31 03:28:14
|
Revision: 807 http://svn.sourceforge.net/fb-contrib/?rev=807&view=rev Author: dbrosius Date: 2007-01-30 19:28:10 -0800 (Tue, 30 Jan 2007) Log Message: ----------- get ready for 3.2.0 Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2007-01-30 08:35:27 UTC (rev 806) +++ trunk/fb-contrib/build.xml 2007-01-31 03:28:10 UTC (rev 807) @@ -20,7 +20,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="3.1.0"/> + <property name="fb-contrib.version" value="3.2.0"/> <target name="clean" description="removes all generated collateral"> <delete dir="${classes.dir}"/> Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-01-30 08:35:27 UTC (rev 806) +++ trunk/fb-contrib/etc/findbugs.xml 2007-01-31 03:28:10 UTC (rev 807) @@ -261,7 +261,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" reports="BAS_BLOATED_ASSIGNMENT_SCOPE" - disabled="true" /> + hidden="true" /> <Detector class="com.mebigfatguy.fbcontrib.detect.SpoiledChildInterfaceImplementor" speed="fast" Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2007-01-30 08:35:27 UTC (rev 806) +++ trunk/fb-contrib/htdocs/index.html 2007-01-31 03:28:10 UTC (rev 807) @@ -48,9 +48,9 @@ <a href="bugdescriptions.html">Bug Descriptions</a> <hr/> - <img id="svn_image" src="flip2.gif" onClick="toggleBlock('svn', 'svn_image');" align="top"/> - Detectors added in svn<br/> - <div id="svn" style="display:block;"> + <img id="v3_2_0_image" src="flip2.gif" onClick="toggleBlock('v3_2_0', 'v3_2_0_image');" align="top"/> + Detectors added in v3.2.0<br/> + <div id="v3_2_0" style="display:block;"> <ul> <li><b>[SCRV] Suspicious Comparator Return Values</b><br/> Looks for classes that implement Comparator or Comparable, and whose compare or compareTo This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-30 08:35:28
|
Revision: 806 http://svn.sourceforge.net/fb-contrib/?rev=806&view=rev Author: dbrosius Date: 2007-01-30 00:35:27 -0800 (Tue, 30 Jan 2007) Log Message: ----------- address bug 1555116 report methods called in finally blocks that may throw exceptions, but that are not handled in try/catch blocks inside the finally block. In fact, it only looks for a try/catch block regardless of catch type, so a few false positives will fall thru, but doing this would be prohibitive. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2007-01-30 06:47:15 UTC (rev 805) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2007-01-30 08:35:27 UTC (rev 806) @@ -21,8 +21,12 @@ import java.util.ArrayList; import java.util.List; +import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.CodeException; +import org.apache.bcel.classfile.ExceptionTable; +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; @@ -150,10 +154,77 @@ .addMethod(this) .addSourceLine(this)); fbInfo.remove(0); + } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE) || (seen == INVOKESPECIAL) || (seen == INVOKESTATIC)) { + try { + JavaClass cls = Repository.lookupClass(getClassConstantOperand()); + Method m = findMethod(cls, getNameConstantOperand(), getSigConstantOperand()); + if (m != null) { + ExceptionTable et = m.getExceptionTable(); + if ((et != null) && (et.getLength() > 0)) { + if (!catchBlockInFinally(fbi)) { + bugReporter.reportBug(new BugInstance( this, "AFBR_ABNORMAL_FINALLY_BLOCK_RETURN", LOW_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + fbInfo.remove(0); + } + } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } } } /** + * finds the method in specified class by name and signature + * + * @param cls the class to look the method in + * @param name the name of the method to look for + * @param sig the signature of the method to look for + * + * @return the Method object for the specified information + */ + private Method findMethod(JavaClass cls, String name, String sig) { + Method[] methods = cls.getMethods(); + for (Method m : methods) { + if (m.getName().equals(name) && m.getSignature().equals(sig)) { + return m; + } + } + + return null; + } + + /** + * looks to see if any try/catch block exists inside this finally block, that + * wrap the current pc. This is a lax check as the try catch block may not + * catch exceptions that are thrown, but doing so would be prohibitively slow. + * But it should catch some problems. + * + * @param fbInfo the finally block the pc is currently in + * + * @return if all exceptions are caught inside this finally block + */ + private boolean catchBlockInFinally(FinallyBlockInfo fbInfo) { + + CodeException[] catchExceptions = getCode().getExceptionTable(); + if ((catchExceptions == null) || (catchExceptions.length == 0)) + return false; + + int pc = getPC(); + for (CodeException ex : catchExceptions) { + if ((ex.getStartPC() <= pc) && (ex.getEndPC() >= pc)) { + if (ex.getStartPC() >= fbInfo.startPC) { + return true; + } + } + } + + return false; + } + + /** * holds the finally block information for a particular method. */ public static class FinallyBlockInfo This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-30 06:47:16
|
Revision: 805 http://svn.sourceforge.net/fb-contrib/?rev=805&view=rev Author: dbrosius Date: 2007-01-29 22:47:15 -0800 (Mon, 29 Jan 2007) Log Message: ----------- remove some false positives because the state wasn't set back after state is SEEN_NEXT, and no appropriate action was taken Modified Paths: -------------- trunk/fb-contrib/samples/USS_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java Modified: trunk/fb-contrib/samples/USS_Sample.java =================================================================== --- trunk/fb-contrib/samples/USS_Sample.java 2007-01-30 06:12:31 UTC (rev 804) +++ trunk/fb-contrib/samples/USS_Sample.java 2007-01-30 06:47:15 UTC (rev 805) @@ -76,4 +76,25 @@ return sarray; } + + public String[] testUssFP6(String s) + { + StringTokenizer st = new StringTokenizer(s, ";"); + int count = st.countTokens(); + String[] sarray = new String[count]; + + int i = 0; + while (st.hasMoreTokens()) + { + String x = st.nextToken(); + if (x.equals("*")) + x = "Star"; + + sarray[i++] = x; + } + + return sarray; + } + + } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-01-30 06:12:31 UTC (rev 804) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-01-30 06:47:15 UTC (rev 805) @@ -217,12 +217,9 @@ } } } - } else if (seen == INVOKEVIRTUAL) { - String clsName = getClassConstantOperand(); - if ("java/lang/StringBuffer".equals(clsName) || "java/lang/StringBuilder".equals(clsName)) { - state = SEEN_NOTHING; - } } + state = SEEN_NOTHING; + break; } } finally { stack.sawOpcode(this, seen); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-30 06:12:31
|
Revision: 804 http://svn.sourceforge.net/fb-contrib/?rev=804&view=rev Author: dbrosius Date: 2007-01-29 22:12:31 -0800 (Mon, 29 Jan 2007) Log Message: ----------- add more explanation for LSYC Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-01-29 17:33:28 UTC (rev 803) +++ trunk/fb-contrib/etc/messages.xml 2007-01-30 06:12:31 UTC (rev 804) @@ -1285,6 +1285,14 @@ <p>This method creates a synchronized collection and store the reference to it in a local variable. As local variables are by definition threadsafe, it seems questionable that this collection needs to be synchronized.</p> + <p> + <table> + <tr><th>If you are using</th><th>consider using</th></tr> + <tr><td>java.util.Vector</td><td>java.util.ArrayList</td></tr> + <tr><td>java.util.Hashtable</td><td>java.util.HashMap</td></tr> + <tr><td>java.lang.StringBuffer</td><td>java.lang.StringBuilder</td></tr> + </table> + </p> ]]> </Details> </BugPattern> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-29 17:33:35
|
Revision: 803 http://svn.sourceforge.net/fb-contrib/?rev=803&view=rev Author: dbrosius Date: 2007-01-29 09:33:28 -0800 (Mon, 29 Jan 2007) Log Message: ----------- better explaination of differences between StringTokenizer and String.split Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-01-28 21:47:38 UTC (rev 802) +++ trunk/fb-contrib/etc/messages.xml 2007-01-29 17:33:28 UTC (rev 803) @@ -1742,8 +1742,15 @@ <![CDATA[ <p>This method uses a StringTokenizer to split up a String and then walks thru the separated elements and builds an array from these enumerated values. It is simpler - and easier to use the String.split method. - </p> + and easier to use the String.split method.</p> + <p>PLEASE NOTE: String.split will return an array of 1 element when passed the + empty string, as opposed to using StringTokenizer which returns false on the first + hasMoreElements/hasMoreTokens call. So you may need to use</p> + <pre> + if (s.length() > 0) + return s.split(";"); + return new String[0]; + </pre> ]]> </Details> </BugPattern> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 21:47:44
|
Revision: 802 http://svn.sourceforge.net/fb-contrib/?rev=802&view=rev Author: dbrosius Date: 2007-01-28 13:47:38 -0800 (Sun, 28 Jan 2007) Log Message: ----------- remove a big false positive area where the implementation of a interface method declares that it DOES NOT throw an exception defined by the interface, and the method that uses this method doesn't handle that type of exception. Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/samples/OCP_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-01-28 21:08:03 UTC (rev 801) +++ trunk/fb-contrib/etc/findbugs.xml 2007-01-28 21:47:38 UTC (rev 802) @@ -41,7 +41,7 @@ reports="CC_CYCLOMATIC_COMPLEXITY" /> <Detector class="com.mebigfatguy.fbcontrib.detect.OverlyConcreteParameter" - speed="moderate" + speed="slow" reports="OCP_OVERLY_CONCRETE_PARAMETER" /> <Detector class="com.mebigfatguy.fbcontrib.detect.ListIndexedIterating" Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-01-28 21:08:03 UTC (rev 801) +++ trunk/fb-contrib/etc/messages.xml 2007-01-28 21:47:38 UTC (rev 802) @@ -66,7 +66,7 @@ <p> Looks for parameters that are defined by classes, but only use methods defined by an implemented interface or super class. Relying on concrete classes in public signatures causes cohesion, and makes low impact changes more difficult.</p> - <p>It is a moderately fast detector</p> + <p>It is a slow detector</p> ]]> </Details> </Detector> Modified: trunk/fb-contrib/samples/OCP_Sample.java =================================================================== --- trunk/fb-contrib/samples/OCP_Sample.java 2007-01-28 21:08:03 UTC (rev 801) +++ trunk/fb-contrib/samples/OCP_Sample.java 2007-01-28 21:47:38 UTC (rev 802) @@ -2,6 +2,7 @@ import java.awt.event.ActionListener; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashSet; import java.util.Iterator; @@ -51,6 +52,8 @@ public static interface A { public void test(); + + public void fp() throws IOException; } public static class B implements A @@ -61,10 +64,20 @@ { } + + public void fp() + { + + } } public void actionPerformed(ActionEvent ae) { } + + public void ocpFalseFPDueToExceptionSig(B b) + { + b.fp(); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 21:08:03 UTC (rev 801) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 21:47:38 UTC (rev 802) @@ -29,6 +29,7 @@ import org.apache.bcel.Constants; import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.CodeException; import org.apache.bcel.classfile.ExceptionTable; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.LocalVariable; @@ -37,6 +38,7 @@ import org.apache.bcel.generic.Type; import com.mebigfatguy.fbcontrib.utils.Integer14; +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; @@ -212,11 +214,8 @@ } } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { - int reg; - if (seen == ALOAD) - reg = this.getRegisterOperand(); - else - reg = seen - ALOAD_0; + int reg = RegisterUtils.getALoadReg(this, seen); + int parm = reg; if (!methodIsStatic) parm--; @@ -254,7 +253,7 @@ parm++; //users expect 1 based parameters String infName = definers.keySet().iterator().next().getClassName(); - bugReporter.reportBug( new BugInstance( this, "OCP_OVERLY_CONCRETE_PARAMETER", NORMAL_PRIORITY) + bugReporter.reportBug( new BugInstance(this, "OCP_OVERLY_CONCRETE_PARAMETER", NORMAL_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(this, 0) @@ -356,6 +355,15 @@ for (MethodInfo mi : methodSigs) { if (methodInfo.equals(mi)) { methodDefined = true; + String[] exceptions = mi.getMethodExceptions(); + if (exceptions != null) { + for (String ex : exceptions) { + if (!isExceptionHandled(ex)) { + methodDefined = false; + break; + } + } + } break; } } @@ -368,6 +376,48 @@ } } + /** + * returns whether this exception is handled either in a try/catch or throws clause at this pc + * + * @param ex the name of the exception + * + * @return whether the exception is handled + */ + private boolean isExceptionHandled(String ex) { + try { + JavaClass thrownEx = Repository.lookupClass(ex); + //First look at the throws clause + ExceptionTable et = getMethod().getExceptionTable(); + if (et != null) { + String[] throwClauseExNames = et.getExceptionNames(); + for (String throwClauseExName : throwClauseExNames) { + JavaClass throwClauseEx = Repository.lookupClass(throwClauseExName); + if (thrownEx.instanceOf(throwClauseEx)) + return true; + } + } + // Next look at the try catch blocks + CodeException[] catchExs = getCode().getExceptionTable(); + if (catchExs != null) { + int pc = getPC(); + for (CodeException catchEx : catchExs) { + if ((pc >= catchEx.getStartPC()) && (pc <= catchEx.getEndPC())) { + int type = catchEx.getCatchType(); + if (type != 0) { + String catchExName = getConstantPool().getConstantString(type, Constants.CONSTANT_Class); + JavaClass catchException = Repository.lookupClass(catchExName); + if (thrownEx.instanceOf(catchException)) + return true; + } + } + } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } + return false; + } + private void removeUselessDefiners(String parmSig, final int reg) { if (parmSig.startsWith("L")) { parmSig = parmSig.substring( 1, parmSig.length() - 1).replace('/', '.'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 21:08:05
|
Revision: 801 http://svn.sourceforge.net/fb-contrib/?rev=801&view=rev Author: dbrosius Date: 2007-01-28 13:08:03 -0800 (Sun, 28 Jan 2007) Log Message: ----------- add toString Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 21:01:52 UTC (rev 800) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 21:08:03 UTC (rev 801) @@ -434,5 +434,10 @@ return true; } + + @Override + public String toString() { + return methodName + methodSig; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 21:01:53
|
Revision: 800 http://svn.sourceforge.net/fb-contrib/?rev=800&view=rev Author: dbrosius Date: 2007-01-28 13:01:52 -0800 (Sun, 28 Jan 2007) Log Message: ----------- inner classes s/b static if possible Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-01-28 21:00:11 UTC (rev 799) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-01-28 21:01:52 UTC (rev 800) @@ -274,7 +274,7 @@ return -1; } - class Loop + static class Loop { public int loopStart; public int loopFinish; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 21:00:36
|
Revision: 799 http://svn.sourceforge.net/fb-contrib/?rev=799&view=rev Author: dbrosius Date: 2007-01-28 13:00:11 -0800 (Sun, 28 Jan 2007) Log Message: ----------- NAB fixes Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2007-01-28 20:58:56 UTC (rev 798) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2007-01-28 21:00:11 UTC (rev 799) @@ -91,7 +91,7 @@ String methodSig = getMethodSig(); if (methodName.equals(methodInfo[0]) && methodSig.endsWith(methodInfo[2]) - && (Type.getArgumentTypes(methodSig).length == Integer.valueOf(methodInfo[1]).intValue())) { + && (Type.getArgumentTypes(methodSig).length == Integer.parseInt(methodInfo[1]))) { stack.resetForMethodEntry(this); indeterminate = false; seenNegative = false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 20:59:11
|
Revision: 798 http://svn.sourceforge.net/fb-contrib/?rev=798&view=rev Author: dbrosius Date: 2007-01-28 12:58:56 -0800 (Sun, 28 Jan 2007) Log Message: ----------- GC fixes Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2007-01-28 20:57:16 UTC (rev 797) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2007-01-28 20:58:56 UTC (rev 798) @@ -185,7 +185,7 @@ if (item.getUserValue() == null) { FieldAnnotation fa = new FieldAnnotation(getClassName(), getNameConstantOperand(), getSigConstantOperand(), false); if (fa != null) - fieldLabels.remove(fa); + fieldLabels.remove(XFactory.createXField(fa)); } } } else if (seen == INVOKESPECIAL) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 20:57:18
|
Revision: 797 http://svn.sourceforge.net/fb-contrib/?rev=797&view=rev Author: dbrosius Date: 2007-01-28 12:57:16 -0800 (Sun, 28 Jan 2007) Log Message: ----------- NAB fixes Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2007-01-28 20:53:12 UTC (rev 796) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2007-01-28 20:57:16 UTC (rev 797) @@ -74,7 +74,7 @@ String percent = System.getProperty(ENVY_PERCENT_PROPERTY); if (percent != null) { try { - envyPercent = Double.valueOf(percent).doubleValue(); + envyPercent = Double.parseDouble(percent); } catch (NumberFormatException nfe) { //Stick with original } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 20:53:12
|
Revision: 796 http://svn.sourceforge.net/fb-contrib/?rev=796&view=rev Author: dbrosius Date: 2007-01-28 12:53:12 -0800 (Sun, 28 Jan 2007) Log Message: ----------- GC fixes Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java 2007-01-28 20:49:56 UTC (rev 795) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java 2007-01-28 20:53:12 UTC (rev 796) @@ -165,12 +165,15 @@ */ public JavaClass findCommonType(Set<JavaClass> classes) throws ClassNotFoundException { Set<JavaClass> possibleCommonTypes = new HashSet<JavaClass>(); - classes.remove("java/lang/Object"); + boolean populate = true; for (JavaClass cls : classes) { - if (cls == null) { //array + if (cls == null) //array return null; - } + + if ("java/lang/Object".equals(cls.getClassName())) + continue; + JavaClass[] infs = cls.getAllInterfaces(); JavaClass[] supers = cls.getSuperClasses(); if (populate) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 20:49:56
|
Revision: 795 http://svn.sourceforge.net/fb-contrib/?rev=795&view=rev Author: dbrosius Date: 2007-01-28 12:49:56 -0800 (Sun, 28 Jan 2007) Log Message: ----------- GC fixes Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2007-01-28 20:43:32 UTC (rev 794) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2007-01-28 20:49:56 UTC (rev 795) @@ -39,6 +39,7 @@ import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.SourceLineAnnotation; import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XFactory; import edu.umd.cs.findbugs.ba.XField; /** @@ -75,7 +76,7 @@ } private BugReporter bugReporter; private OpcodeStack stack; - private Set<FieldAnnotation> fieldLabels; + private Set<XField> fieldLabels; private Map<Integer, SourceLineAnnotation> localLabels; /** @@ -105,10 +106,10 @@ } stack = new OpcodeStack(); - fieldLabels = new HashSet<FieldAnnotation>(); + fieldLabels = new HashSet<XField>(); localLabels = new HashMap<Integer, SourceLineAnnotation>(); super.visitClassContext(classContext); - for (FieldAnnotation fa : fieldLabels) { + for (XField fa : fieldLabels) { bugReporter.reportBug(new BugInstance(this, "S508C_NO_SETLABELFOR", NORMAL_PRIORITY) .addClass(this) .addField(fa)); @@ -132,7 +133,8 @@ String fieldSig = obj.getSignature(); if ("Ljavax/swing/JLabel;".equals(fieldSig)) { FieldAnnotation fa = FieldAnnotation.fromVisitedField(this); - fieldLabels.add(fa); + + fieldLabels.add(XFactory.createXField(fa)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 20:43:31
|
Revision: 794 http://svn.sourceforge.net/fb-contrib/?rev=794&view=rev Author: dbrosius Date: 2007-01-28 12:43:32 -0800 (Sun, 28 Jan 2007) Log Message: ----------- BAS fixes Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-01-28 20:42:31 UTC (rev 793) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-01-28 20:43:32 UTC (rev 794) @@ -111,9 +111,9 @@ return; } if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { - int reg = RegisterUtils.getAStoreReg(this, seen); if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); + int reg = RegisterUtils.getAStoreReg(this, seen); regValueType.put(Integer.valueOf(reg), (Integer)item.getUserValue()); } state = SEEN_NOTHING; @@ -129,9 +129,9 @@ return; } if ((seen == ISTORE) || ((seen >= ISTORE_0) && (seen <= ISTORE_3))) { - int reg = RegisterUtils.getStoreReg(this, seen); if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); + int reg = RegisterUtils.getStoreReg(this, seen); regValueType.put(Integer.valueOf(reg), (Integer)item.getUserValue()); } state = SEEN_NOTHING; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 20:42:31
|
Revision: 793 http://svn.sourceforge.net/fb-contrib/?rev=793&view=rev Author: dbrosius Date: 2007-01-28 12:42:31 -0800 (Sun, 28 Jan 2007) Log Message: ----------- BAS fixes Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2007-01-28 20:37:48 UTC (rev 792) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2007-01-28 20:42:31 UTC (rev 793) @@ -349,9 +349,10 @@ return (syncCollections.contains(getClassConstantOperand())); } } else if (seen == INVOKESTATIC) { - String methodName = getNameConstantOperand(); - return "java/util/Collections".equals(getClassConstantOperand()) - && ("synchronizedMap".equals(methodName) || "synchronizedSet".equals(methodName)); + if ("java/util/Collections".equals(getClassConstantOperand())) { + String methodName = getNameConstantOperand(); + return ("synchronizedMap".equals(methodName) || "synchronizedSet".equals(methodName)); + } } return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-01-28 20:37:48
|
Revision: 792 http://svn.sourceforge.net/fb-contrib/?rev=792&view=rev Author: dbrosius Date: 2007-01-28 12:37:48 -0800 (Sun, 28 Jan 2007) Log Message: ----------- move to first class MethodInfo, to start pulling in exception stuff Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 20:14:52 UTC (rev 791) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2007-01-28 20:37:48 UTC (rev 792) @@ -29,6 +29,7 @@ import org.apache.bcel.Constants; import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.ExceptionTable; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.LocalVariable; import org.apache.bcel.classfile.LocalVariableTable; @@ -52,7 +53,7 @@ { private BugReporter bugReporter; private JavaClass[] interfaces; - private Map<Integer, Map<JavaClass, List<String>>> parameterDefiners; + private Map<Integer, Map<JavaClass, List<MethodInfo>>> parameterDefiners; private Set<Integer> usedParameters; private JavaClass objectClass; private OpcodeStack stack; @@ -78,7 +79,7 @@ public void visitClassContext(ClassContext classContext) { try { interfaces = classContext.getJavaClass().getAllInterfaces(); - parameterDefiners = new HashMap<Integer, Map<JavaClass, List<String>>>(); + parameterDefiners = new HashMap<Integer, Map<JavaClass, List<MethodInfo>>>(); usedParameters = new HashSet<Integer>(); stack = new OpcodeStack(); super.visitClassContext(classContext); @@ -228,16 +229,16 @@ } private void reportBugs() { - Iterator<Map.Entry<Integer, Map<JavaClass, List<String>>>> it = parameterDefiners.entrySet().iterator(); + Iterator<Map.Entry<Integer, Map<JavaClass, List<MethodInfo>>>> it = parameterDefiners.entrySet().iterator(); while (it.hasNext()) { - Map.Entry<Integer, Map<JavaClass, List<String>>> entry = it.next(); + Map.Entry<Integer, Map<JavaClass, List<MethodInfo>>> entry = it.next(); Integer reg = entry.getKey(); if (!usedParameters.contains(reg)) { it.remove(); continue; } - Map<JavaClass, List<String>> definers = entry.getValue(); + Map<JavaClass, List<MethodInfo>> definers = entry.getValue(); definers.remove(objectClass); if (definers.size() > 0) { String name = ""; @@ -286,7 +287,7 @@ JavaClass cls = Repository.lookupClass(clsName); if (cls.isClass()) { - Map<JavaClass, List<String>> definers = getClassDefiners(cls); + Map<JavaClass, List<MethodInfo>> definers = getClassDefiners(cls); if (definers.size() > 0) { parameterDefiners.put( Integer14.valueOf(i + (methodIsStatic ? 0 : 1)), definers ); @@ -306,14 +307,14 @@ * @return a map of (method name)(method sig) by interface * @throws ClassNotFoundException if unable to load the class */ - private Map<JavaClass, List<String>> getClassDefiners(final JavaClass cls) + private Map<JavaClass, List<MethodInfo>> getClassDefiners(final JavaClass cls) throws ClassNotFoundException { - Map<JavaClass, List<String>> definers = new HashMap<JavaClass, List<String>>(); + Map<JavaClass, List<MethodInfo>> definers = new HashMap<JavaClass, List<MethodInfo>>(); for (JavaClass ci : cls.getAllInterfaces()) { if ("java.lang.Comparable".equals(ci.getClassName())) continue; - List<String> methodInfos = getPublicMethodInfos(ci); + List<MethodInfo> methodInfos = getPublicMethodInfos(ci); if (methodInfos.size() > 0) { definers.put(ci, methodInfos); } @@ -327,13 +328,13 @@ * @param cls the class to look for methods * @return a map of (method name)(method signature) */ - private List<String> getPublicMethodInfos(final JavaClass cls) { - List<String> methodInfos = new ArrayList<String>(); + private List<MethodInfo> getPublicMethodInfos(final JavaClass cls) { + List<MethodInfo> methodInfos = new ArrayList<MethodInfo>(); Method[] methods = cls.getMethods(); for (Method m : methods) { if ((m.getAccessFlags() & (Constants.ACC_PUBLIC|Constants.ACC_PROTECTED)) != 0) { - String methodInfo = m.getName() + m.getSignature(); - methodInfos.add(methodInfo); + ExceptionTable et = m.getExceptionTable(); + methodInfos.add(new MethodInfo(m.getName(), m.getSignature(), et == null ? null : et.getExceptionNames())); } } return methodInfos; @@ -341,18 +342,18 @@ private void removeUselessDefiners(final int reg) { - Map<JavaClass, List<String>> definers = parameterDefiners.get(Integer14.valueOf(reg)); + Map<JavaClass, List<MethodInfo>> definers = parameterDefiners.get(Integer14.valueOf(reg)); if ((definers != null) && (definers.size() > 0)) { String methodSig = getSigConstantOperand(); String methodName = getNameConstantOperand(); - String methodInfo = methodName + methodSig; + MethodInfo methodInfo = new MethodInfo(methodName, methodSig, null); - Iterator<List<String>> it = definers.values().iterator(); + Iterator<List<MethodInfo>> it = definers.values().iterator(); while (it.hasNext()) { boolean methodDefined = false; - List<String> methodSigs = it.next(); + List<MethodInfo> methodSigs = it.next(); - for (String mi : methodSigs) { + for (MethodInfo mi : methodSigs) { if (methodInfo.equals(mi)) { methodDefined = true; break; @@ -375,7 +376,7 @@ return; } - Map<JavaClass, List<String>> definers = parameterDefiners.get(Integer14.valueOf(reg)); + Map<JavaClass, List<MethodInfo>> definers = parameterDefiners.get(Integer14.valueOf(reg)); if ((definers != null) && (definers.size() > 0)) { Iterator<JavaClass> it = definers.keySet().iterator(); while (it.hasNext()) { @@ -389,4 +390,49 @@ } } } + + public static class MethodInfo + { + private String methodName; + private String methodSig; + private String[] methodExceptions; + + public MethodInfo(String name, String sig, String[] excs) { + methodName = name; + methodSig = sig; + methodExceptions = excs; + } + + public String getMethodName() { + return methodName; + } + + public String getMethodSignature() { + return methodSig; + } + + public String[] getMethodExceptions() { + return methodExceptions; + } + + @Override + public int hashCode() { + return methodName.hashCode() ^ methodSig.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof MethodInfo)) + return false; + + MethodInfo that = (MethodInfo)o; + + if (!methodName.equals(that.methodName)) + return false; + if (!methodSig.equals(that.methodSig)) + return false; + + return true; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |