[Fb-contrib-commit] SF.net SVN: fb-contrib: [817] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2007-02-02 05:06:55
|
Revision: 817 http://svn.sourceforge.net/fb-contrib/?rev=817&view=rev Author: dbrosius Date: 2007-02-01 21:06:53 -0800 (Thu, 01 Feb 2007) Log Message: ----------- starting to work Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/samples/SJVU_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2007-02-01 09:38:22 UTC (rev 816) +++ trunk/fb-contrib/build.xml 2007-02-02 05:06:53 UTC (rev 817) @@ -81,6 +81,17 @@ <classpath refid="fb-contrib.classpath"/> <classpath refid="fb-contrib.samples.classpath"/> </javac> + <delete file="${samples.dir}/SJVU_Sample.class"/> + <javac srcdir="${samples.dir}" + destdir="${samples.dir}" + source="1.4" + target="1.4" + deprecation="${javac.deprecation}" + debug="${javac.debug}"> + <include name="SJVU_Sample.java"/> + <classpath refid="fb-contrib.classpath"/> + <classpath refid="fb-contrib.samples.classpath"/> + </javac> </target> <target name="jar" depends="compile" description="produces the fb-contrib jar file"> Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-02-01 09:38:22 UTC (rev 816) +++ trunk/fb-contrib/etc/findbugs.xml 2007-02-02 05:06:53 UTC (rev 817) @@ -277,9 +277,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousJDKVersionUse" speed="slow" - reports="SJVU_SUSPICIOUS_JDK_VERSION_USE" - hidden="true" - disabled="true" /> + reports="SJVU_SUSPICIOUS_JDK_VERSION_USE" /> <!-- BugPattern --> Modified: trunk/fb-contrib/samples/SJVU_Sample.java =================================================================== --- trunk/fb-contrib/samples/SJVU_Sample.java 2007-02-01 09:38:22 UTC (rev 816) +++ trunk/fb-contrib/samples/SJVU_Sample.java 2007-02-02 05:06:53 UTC (rev 817) @@ -4,5 +4,9 @@ public void test14using15(int i) { Integer ii = Integer.valueOf(i); + StringBuilder sb = new StringBuilder(); + sb.append(ii.intValue()); } + + } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2007-02-01 09:38:22 UTC (rev 816) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2007-02-02 05:06:53 UTC (rev 817) @@ -18,12 +18,12 @@ */ package com.mebigfatguy.fbcontrib.detect; +import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; +import java.io.UnsupportedEncodingException; import java.net.URL; -import java.net.URLClassLoader; import java.net.URLDecoder; import java.util.HashMap; import java.util.HashSet; @@ -31,6 +31,8 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import org.apache.bcel.Constants; import org.apache.bcel.classfile.ClassParser; @@ -61,8 +63,8 @@ private Map<Integer, Map<String, Set<String>>> validMethodsByVersion; private Map<String, String> superNames; private File jdksRoot = null; - JavaClass cls; - private URLClassLoader jdkLoader; + private ZipFile jdkZip; + private JavaClass cls; private Integer clsMajorVersion; private BugReporter bugReporter; @@ -80,14 +82,20 @@ clsMajorVersion = Integer14.valueOf(cls.getMajor()); File rtJar = getRTJarFile(cls); if (rtJar != null) { - jdkLoader = new URLClassLoader(new URL[] {rtJar.toURL()}); + jdkZip = new ZipFile(rtJar); super.visitClassContext(classContext); } - } catch (MalformedURLException mue) { - //Hmm, what to do + } catch (Exception ze) { + // Hmm what to do? } finally { cls = null; - jdkLoader = null; + clsMajorVersion = null; + try { + if (jdkZip != null) + jdkZip.close(); + } catch (IOException ioe) { + } + jdkZip = null; } } @@ -98,8 +106,7 @@ InputStream is = null; try { - if ((seen == INVOKEVIRTUAL) - || (seen == INVOKEINTERFACE) + if ((seen == INVOKEVIRTUAL) //Interfaces are more difficult, ignore for now || (seen == INVOKESTATIC) || (seen == INVOKESPECIAL)) { clsName = getClassConstantOperand(); @@ -115,7 +122,8 @@ bugReporter.reportBug(new BugInstance(this, "SJVU_SUSPICIOUS_JDK_VERSION_USE", HIGH_PRIORITY) .addClass(this) .addMethod(this) - .addSourceLine(this)); + .addSourceLine(this) + .addCalledMethod(this)); } } } @@ -137,27 +145,35 @@ try { Set<String> methodInfos = validMethods.get(clsName); if (methodInfos == null) { - is = jdkLoader.getResourceAsStream(clsName + ".class"); - if (is != null) { - ClassParser parser = new ClassParser(is, clsName); - JavaClass calledClass = parser.parse(); - - superNames.put(clsName, calledClass.getSuperclassName().replace('.', '/')); - Method[] methods = calledClass.getMethods(); - - methodInfos = new HashSet<String>(); - validMethods.put(clsName, methodInfos); - - for (Method m : methods) { - if (!m.isPrivate()) + + ZipEntry ze = jdkZip.getEntry(clsName + ".class"); + if (ze != null) { + is = new BufferedInputStream(jdkZip.getInputStream(ze)); + if (is != null) { + ClassParser parser = new ClassParser(is, clsName); + JavaClass calledClass = parser.parse(); + + superNames.put(clsName, calledClass.getSuperclassName().replace('.', '/')); + Method[] methods = calledClass.getMethods(); + + methodInfos = new HashSet<String>(); + validMethods.put(clsName, methodInfos); + + for (Method m : methods) { methodInfos.add(m.getName() + m.getSignature()); + } + } - + else { + return true; + } + } else if (clsName.startsWith("java/")) { + bugReporter.reportBug(new BugInstance(this, "SJVU_SUSPICIOUS_JDK_VERSION_USE", HIGH_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this) + .addClass(clsName)); } - else { - return true; - } - } String wantedMethod = getNameConstantOperand() + getSigConstantOperand(); @@ -178,7 +194,7 @@ } } - private File getRTJarFile(JavaClass cls) { + private File getRTJarFile(JavaClass cls){ String versionStr = verRegEx.get(clsMajorVersion); if (versionStr == null) return null; @@ -205,7 +221,12 @@ if (jdksRoot.getParentFile() == null) return null; - jdksRoot = new File(URLDecoder.decode(jdksRoot.getParentFile().getPath())); + try { + String encoding = System.getProperty("file.encoding"); + jdksRoot = new File(URLDecoder.decode(jdksRoot.getParentFile().getPath(), encoding)); + } catch (UnsupportedEncodingException uee) { + return null; + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |