[Fb-contrib-commit] SF.net SVN: fb-contrib:[1711] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2012-02-02 18:00:48
|
Revision: 1711
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1711&view=rev
Author: dbrosius
Date: 2012-02-02 18:00:41 +0000 (Thu, 02 Feb 2012)
Log Message:
-----------
update from github - thanks Bhaskar Maddala
Modified Paths:
--------------
trunk/fb-contrib/.classpath
trunk/fb-contrib/build.xml
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/samples/BRPI_Sample.java
trunk/fb-contrib/samples/CCNE_Sample.java
trunk/fb-contrib/samples/CSBTS_StringToStringSample.java
trunk/fb-contrib/samples/samples.fbp
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BackportReusePublicIdentifiers.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CompareClassNameEquals.java
Modified: trunk/fb-contrib/.classpath
===================================================================
--- trunk/fb-contrib/.classpath 2012-01-21 03:02:07 UTC (rev 1710)
+++ trunk/fb-contrib/.classpath 2012-02-02 18:00:41 UTC (rev 1711)
@@ -2,17 +2,18 @@
<classpath>
<classpathentry excluding="**/*.*" kind="src" path="etc"/>
<classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="samples"/>
+ <classpathentry excluding="lib/" kind="src" path="samples"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="lib/annotations-2.0.0.jar"/>
<classpathentry kind="lib" path="lib/asm-tree-3.3.1.jar"/>
<classpathentry kind="lib" path="lib/bcel-2.0.0.jar"/>
- <classpathentry kind="lib" path="lib/findbugs-2.0.0.jar"/>
+ <classpathentry kind="lib" path="lib/findbugs-2.0.0.jar" sourcepath="findbugs-2.0.0-source.zip"/>
<classpathentry kind="lib" path="samples/lib/commons-lang3-3.1.jar"/>
<classpathentry kind="lib" path="samples/lib/jsp-api-2.2.1.jar"/>
<classpathentry kind="lib" path="samples/lib/junit-4.10.jar"/>
<classpathentry kind="lib" path="samples/lib/log4j-1.2.16.jar"/>
<classpathentry kind="lib" path="samples/lib/servlet-api-3.0.1.jar"/>
+ <classpathentry kind="lib" path="samples/lib/backport-util-concurrent-3.1.jar"/>
<classpathentry kind="output" path="classes"/>
</classpath>
Modified: trunk/fb-contrib/build.xml
===================================================================
--- trunk/fb-contrib/build.xml 2012-01-21 03:02:07 UTC (rev 1710)
+++ trunk/fb-contrib/build.xml 2012-02-02 18:00:41 UTC (rev 1711)
@@ -27,23 +27,25 @@
<property name="annotations.version" value="2.0.0"/>
<property name="asm-tree.version" value="3.3.1"/>
- <property name="findbugs-url" value="http://repo1.maven.org/maven2/com/google/code/findbugs/findbugs/${findbugs.version}/findbugs-${findbugs.version}.jar"/>
- <property name="findbugs-bcel-url" value="http://repo1.maven.org/maven2/com/google/code/findbugs/bcel/${findbugs-bcel.version}/bcel-${findbugs-bcel.version}.jar"/>
- <property name="annotations-url" value="http://repo1.maven.org/maven2/com/google/code/findbugs/annotations/${annotations.version}/annotations-${annotations.version}.jar"/>
- <property name="asm-tree-url" value="http://repo1.maven.org/maven2/asm/asm-tree/${asm-tree.version}/asm-tree-${asm-tree.version}.jar"/>
+ <property name="findbugs-url" value="http://repo1.maven.org/maven2/com/google/code/findbugs/findbugs/${findbugs.version}/findbugs-${findbugs.version}.jar"/>
+ <property name="findbugs-bcel-url" value="http://repo1.maven.org/maven2/com/google/code/findbugs/bcel/${findbugs-bcel.version}/bcel-${findbugs-bcel.version}.jar"/>
+ <property name="annotations-url" value="http://repo1.maven.org/maven2/com/google/code/findbugs/annotations/${annotations.version}/annotations-${annotations.version}.jar"/>
+ <property name="asm-tree-url" value="http://repo1.maven.org/maven2/asm/asm-tree/${asm-tree.version}/asm-tree-${asm-tree.version}.jar"/>
- <!-- properties for samples lib dependencies -->
- <property name="commons-lang3.version" value="3.1"/>
- <property name="jsp-api.version" value="2.2.1" />
- <property name="junit.version" value="4.10" />
- <property name="log4j.version" value="1.2.16" />
- <property name="servlet-api.version" value="3.0.1" />
+ <!-- properties for samples lib dependencies -->
+ <property name="commons-lang3.version" value="3.1"/>
+ <property name="jsp-api.version" value="2.2.1" />
+ <property name="junit.version" value="4.10" />
+ <property name="log4j.version" value="1.2.16" />
+ <property name="servlet-api.version" value="3.0.1" />
+ <property name="backport-concurrent.version" value="3.1" />
- <property name="commons-lang3-url" value="http://repo1.maven.org/maven2/org/apache/commons/commons-lang3/${commons-lang3.version}/commons-lang3-${commons-lang3.version}.jar"/>
- <property name="jsp-api-url" value="http://repo1.maven.org/maven2/javax/servlet/jsp/javax.servlet.jsp-api/${jsp-api.version}/javax.servlet.jsp-api-${jsp-api.version}.jar" />
- <property name="junit-url" value="http://repo1.maven.org/maven2/junit/junit/${junit.version}/junit-${junit.version}.jar"/>
- <property name="log4j-url" value="http://repo1.maven.org/maven2/log4j/log4j/${log4j.version}/log4j-${log4j.version}.jar"/>
- <property name="servlet-api-url" value="http://repo1.maven.org/maven2/javax/servlet/javax.servlet-api/${servlet-api.version}/javax.servlet-api-${servlet-api.version}.jar"/>
+ <property name="commons-lang3-url" value="http://repo1.maven.org/maven2/org/apache/commons/commons-lang3/${commons-lang3.version}/commons-lang3-${commons-lang3.version}.jar"/>
+ <property name="jsp-api-url" value="http://repo1.maven.org/maven2/javax/servlet/jsp/javax.servlet.jsp-api/${jsp-api.version}/javax.servlet.jsp-api-${jsp-api.version}.jar" />
+ <property name="junit-url" value="http://repo1.maven.org/maven2/junit/junit/${junit.version}/junit-${junit.version}.jar"/>
+ <property name="log4j-url" value="http://repo1.maven.org/maven2/log4j/log4j/${log4j.version}/log4j-${log4j.version}.jar"/>
+ <property name="servlet-api-url" value="http://repo1.maven.org/maven2/javax/servlet/javax.servlet-api/${servlet-api.version}/javax.servlet-api-${servlet-api.version}.jar"/>
+ <property name="backport-concurrent-url" value="http://repo1.maven.org/maven2/backport-util-concurrent/backport-util-concurrent/${backport-concurrent.version}/backport-util-concurrent-${backport-concurrent.version}.jar" />
<target name="clean" description="removes all generated collateral">
<delete dir="${classes.dir}"/>
@@ -76,6 +78,8 @@
<pathelement location="${sampleslib.dir}/servlet-api-${servlet-api.version}.jar"/>
<pathelement location="${sampleslib.dir}/log4j-${log4j.version}.jar"/>
<pathelement location="${sampleslib.dir}/commons-lang3-${commons-lang3.version}.jar"/>
+ <pathelement location="${sampleslib.dir}/commons-lang3-${commons-lang3.version}.jar"/>
+ <pathelement location="${sampleslib.dir}/backport-util-concurrent-${backport-concurrent.version}.jar"/>
</path>
<mkdir dir="${classes.dir}/com"/>
<mkdir dir="${classes.dir}/com/mebigfatguy"/>
@@ -107,6 +111,10 @@
<target name="servlet-api-check">
<available file="${basedir}/samples/lib/servlet-api-${servlet-api.version}.jar" property="servlet-api-exists"/>
</target>
+
+ <target name="backport-concurrent-check">
+ <available file="${basedir}/samples/lib/backport-util-concurrent-${backport-concurrent.version}.jar" property="backport-concurrent-exists" />
+ </target>
<target name="jsp-api-check">
<available file="${basedir}/samples/lib/jsp-api-${jsp-api.version}.jar" property="jsp-api-exists"/>
@@ -143,7 +151,11 @@
<target name="install-servlet-api" depends="servlet-api-check" unless="servlet-api-exists" description="installs servlet-api into samples/lib">
<get src="${servlet-api-url}" dest="${basedir}/samples/lib/servlet-api-${servlet-api.version}.jar" verbose="true" ignoreerrors="true"/>
</target>
-
+
+ <target name="install-backport-concurrent" depends="backport-concurrent-check" unless="backport-concurrent-exists" description="installs backport-concurrent into samples/lib">
+ <get src="${backport-concurrent-url}" dest="${basedir}/samples/lib/backport-util-concurrent-${backport-concurrent.version}.jar" verbose="true" ignoreerrors="true"/>
+ </target>
+
<target name="install-jsp-api" depends="jsp-api-check" unless="jsp-api-exists" description="installs jsp-api into samples/lib">
<get src="${jsp-api-url}" dest="${basedir}/samples/lib/jsp-api-${jsp-api.version}.jar" verbose="true" ignoreerrors="true"/>
</target>
@@ -156,7 +168,7 @@
<get src="${junit-url}" dest="${basedir}/samples/lib/junit-${junit.version}.jar" verbose="true" ignoreerrors="true"/>
</target>
- <target name="pull" depends="install-findbugs, install-findbugs-bcel, install-annotations, install-asm-tree, install-commons-lang3, install-servlet-api, install-jsp-api, install-log4j, install-junit" description="pull 3rdparty jars to the lib directory"/>
+ <target name="pull" depends="install-findbugs, install-findbugs-bcel, install-annotations, install-asm-tree, install-commons-lang3, install-servlet-api, install-backport-concurrent, install-jsp-api, install-log4j, install-junit" description="pull 3rdparty jars to the lib directory"/>
<target name="validate_xml" depends="-init" description="validates the xml files">
<xmlvalidate lenient="false" failonerror="yes">
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2012-01-21 03:02:07 UTC (rev 1710)
+++ trunk/fb-contrib/etc/findbugs.xml 2012-02-02 18:00:41 UTC (rev 1711)
@@ -227,6 +227,12 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.CommonsEqualsBuilderToEquals" speed="fast" reports="CEBE_COMMONS_EQUALS_BUILDER_ISEQUALS" />
<Detector class="com.mebigfatguy.fbcontrib.detect.CommonsHashcodeBuilderToHashcode" speed="fast" reports="CHTH_COMMONS_HASHCODE_BUILDER_TOHASHCODE" />
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.CommonsStringBuilderToString" speed="fast" reports="CSBTS_COMMONS_STRING_BUILDER_TOSTRING" />
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.CompareClassNameEquals" speed="fast" reports="CCNE_COMPARE_CLASS_EQUALS_NAME" />
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.BackportReusePublicIdentifiers" speed="fast" reports="BRPI_BACKPORT_REUSE_PUBLIC_IDENTIFIERS" />
<!-- BugPattern -->
@@ -397,4 +403,7 @@
<BugPattern abbrev="STB" type="STB_STACKED_TRY_BLOCKS" category="STYLE" experimental="true" />
<BugPattern abbrev="CEBE" type="CEBE_COMMONS_EQUALS_BUILDER_ISEQUALS" category="CORRECTNESS" />
<BugPattern abbrev="CHTH" type="CHTH_COMMONS_HASHCODE_BUILDER_TOHASHCODE" category="CORRECTNESS" />
+ <BugPattern abbrev="CSBTS" type="CSBTS_COMMONS_STRING_BUILDER_TOSTRING" category="CORRECTNESS" />
+ <BugPattern abbrev="CCNE" type="CCNE_COMPARE_CLASS_EQUALS_NAME" category="CORRECTNESS" />
+ <BugPattern abbrev="BRPI" type="BRPI_BACKPORT_REUSE_PUBLIC_IDENTIFIERS" category ="PERFORMANCE" />
</FindbugsPlugin>
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2012-01-21 03:02:07 UTC (rev 1710)
+++ trunk/fb-contrib/etc/messages.xml 2012-02-02 18:00:41 UTC (rev 1711)
@@ -1237,6 +1237,40 @@
</Details>
</Detector>
+ <Detector class="com.mebigfatguy.fbcontrib.detect.CommonsStringBuilderToString">
+ <Details>
+ <![CDATA[
+ <p>This detector looks for uses for Commons-lang ToStringBuilder where the
+ result of toString() is returned without an intermediate invocation of toString().</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.CompareClassNameEquals">
+ <Details>
+ <![CDATA[
+ <p> In a JVM, Two classes are the same class (and consequently the same type) if
+ they are loaded by the same class loader, and they have the same fully
+ qualified name [JVMSpec 1999].
+
+ Comparing class name ignores the class loader.
+ </p>
+ ]]>
+ </Details>
+ </Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.BackportReusePublicIdentifiers">
+ <Details>
+ <![CDATA[
+ <p> Detects use of Backport Utils concurrent classes. Updated/Efficient version of these
+ classes are available in versions of the JDK 5.0 and higher, and these
+ classes should only be used if you are targeting JDK 1.4 and lower.
+ </p>
+ ]]>
+ </Details>
+ </Detector>
+
<!-- BugPattern -->
<BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING">
@@ -3380,8 +3414,47 @@
instead of calling the method toHashCode().</p>
]]>
</Details>
- </BugPattern>
+ </BugPattern>
+ <BugPattern type="CSBTS_COMMONS_STRING_BUILDER_TOSTRING">
+ <ShortDescription>Method returns the result of invoking toString() without intermediate invocation of append() in ToStringBuilder</ShortDescription>
+ <LongDescription>Method {1} returns the result of invoking toString() without intermediate invocation of append() in ToStringBuilder</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method returns the result of toString() on ToStringBuilder without an
+ intermediate invocation of append()</p>
+ ]]>
+ </Details>
+ </BugPattern>
+
+ <BugPattern type="CCNE_COMPARE_CLASS_EQUALS_NAME">
+ <ShortDescription>Method compares class name instead of comparing class</ShortDescription>
+ <LongDescription>Method {1} compares class name instead of comparing the class</LongDescription>
+ <Details>
+ <![CDATA[
+ <p> In a JVM, Two classes are the same class (and consequently the same type) if
+ they are loaded by the same class loader, and they have the same fully
+ qualified name [JVMSpec 1999].
+
+ Comparing class name ignores the class loader.
+ </p>
+ ]]>
+ </Details>
+ </BugPattern>
+
+ <BugPattern type="BRPI_BACKPORT_REUSE_PUBLIC_IDENTIFIERS">
+ <ShortDescription>Method uses backport concurrency utils</ShortDescription>
+ <LongDescription>Method {1} backport concurrency utils</LongDescription>
+ <Details>
+ <![CDATA[
+ <p> Detects use of Backport Utils concurrent classes. Updated/Efficient version of these
+ classes are available in versions of the JDK 5.0 and higher, and these
+ classes should only be used if you are targeting JDK 1.4 and lower.
+ </p>
+ ]]>
+ </Details>
+ </BugPattern>
+
<!-- BugCode -->
<BugCode abbrev="ISB">Inefficient String Buffering</BugCode>
@@ -3485,4 +3558,8 @@
<BugCode abbrev="LGO">Lingering Graphics Object</BugCode>
<BugCode abbrev="STB">Stacked Try Blocks</BugCode>
<BugCode abbrev="CEBE">Commons EqualsBuilder To Equals</BugCode>
+ <BugCode abbrev="CHTH">Commons HashCodeBuilder To hashCode</BugCode>
+ <BugCode abbrev="CSBTS">Commons ToStringBuilder To String</BugCode>
+ <BugCode abbrev="CCNE">Compare class name equals</BugCode>
+ <BugCode abbrev="BRPI">Backport concurrent reuse of public identifiers</BugCode>
</MessageCollection>
Added: trunk/fb-contrib/samples/BRPI_Sample.java
===================================================================
--- trunk/fb-contrib/samples/BRPI_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/BRPI_Sample.java 2012-02-02 18:00:41 UTC (rev 1711)
@@ -0,0 +1,11 @@
+import edu.emory.mathcs.backport.java.util.Collections;
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+import edu.emory.mathcs.backport.java.util.concurrent.Executors;
+
+public class BRPI_Sample {
+ public static void main(String[] arg) {
+ Collections.emptySet();
+ Executors.newCachedThreadPool();
+ new ConcurrentHashMap();
+ }
+}
Property changes on: trunk/fb-contrib/samples/BRPI_Sample.java
___________________________________________________________________
Added: svn-eol-style
+ native
Added: svn:mime-type
+ text/plain
Added: eol-style
+ native
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/samples/CCNE_Sample.java
===================================================================
--- trunk/fb-contrib/samples/CCNE_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/CCNE_Sample.java 2012-02-02 18:00:41 UTC (rev 1711)
@@ -0,0 +1,8 @@
+public class CCNE_Sample {
+ public void compareClassEquals() {
+ Object o = new CCNE_Sample();
+ Object p = new CCNE_Sample();
+ System.out.println(o.getClass().getName()
+ .equals(p.getClass().getName()));
+ }
+}
Property changes on: trunk/fb-contrib/samples/CCNE_Sample.java
___________________________________________________________________
Added: svn-eol-style
+ native
Added: svn:mime-type
+ text/plain
Added: eol-style
+ native
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/samples/CSBTS_StringToStringSample.java
===================================================================
--- trunk/fb-contrib/samples/CSBTS_StringToStringSample.java (rev 0)
+++ trunk/fb-contrib/samples/CSBTS_StringToStringSample.java 2012-02-02 18:00:41 UTC (rev 1711)
@@ -0,0 +1,59 @@
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+public class CSBTS_StringToStringSample {
+ static class Person {
+ String name;
+ int age;
+
+ Person(String name, int age) {
+ this.name = name;
+ this.age = age;
+ }
+
+ @Override
+ public String toString() {
+ // INCORRECT USAGE : The same as invoking Object.toString()
+ // return new ToStringBuilder(this).toString();
+ // Consider using for non final classes to support a
+ // string representation for derived types
+ // return ToStringBuilder.reflectionToString(this);
+ // Use for final classes most efficient solution
+ return new ToStringBuilder(this).append("name", name)
+ .append("age", age).toString();
+ }
+ }
+
+ private enum SEX {
+ Male, Female;
+ }
+
+ public final static class GenderPerson extends Person {
+ private SEX sex;
+
+ GenderPerson(String name, int age, SEX sex) {
+ super(name, age);
+ this.sex = sex;
+ }
+ }
+
+ public static void main(String[] args) {
+ Person p = new Person("John Doe", 2);
+ ToStringBuilder x = new ToStringBuilder(p);
+ ToStringBuilder y = new ToStringBuilder(p);
+ // INCORRECT USAGE : The same as invoking Object.toString
+ System.out.println("P " + new ToStringBuilder(p).toString());
+ // Consider using for non final classes to support a string
+ // representation for derived types
+ System.out.println("P " + ToStringBuilder.reflectionToString(p));
+ GenderPerson p2 = new GenderPerson("Jane Doe", 2, SEX.Female);
+ System.out
+ .println("GP "
+ + new ToStringBuilder(p2).append("name", p2.name)
+ .append("age", p2.age).append("sex", p2.sex)
+ .toString());
+ // Y now has an append
+ y.append("name", p.name);
+ System.out.println("P - Once Again " + y.toString());
+ System.out.println("P - Again " + x.toString());
+ }
+}
Property changes on: trunk/fb-contrib/samples/CSBTS_StringToStringSample.java
___________________________________________________________________
Added: svn-eol-style
+ native
Added: svn:mime-type
+ text/plain
Added: eol-style
+ native
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/samples/samples.fbp
===================================================================
--- trunk/fb-contrib/samples/samples.fbp (rev 0)
+++ trunk/fb-contrib/samples/samples.fbp 2012-02-02 18:00:41 UTC (rev 1711)
@@ -0,0 +1,12 @@
+<Project projectName="">
+ <Jar>.</Jar>
+ <AuxClasspathEntry>./lib/jsp-api.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>./lib/junit.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>./lib/log4j.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>./lib/servlet-api.jar</AuxClasspathEntry>
+ <SrcDir>.</SrcDir>
+ <SuppressionFilter>
+ <LastVersion value="-1" relOp="NEQ"/>
+ </SuppressionFilter>
+ <Cloud id="1"></Cloud>
+</Project>
Property changes on: trunk/fb-contrib/samples/samples.fbp
___________________________________________________________________
Added: svn-eol-style
+ native
Added: svn:executable
+ *
Added: svn:mime-type
+ text/plain
Added: eol-style
+ native
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BackportReusePublicIdentifiers.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BackportReusePublicIdentifiers.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BackportReusePublicIdentifiers.java 2012-02-02 18:00:41 UTC (rev 1711)
@@ -0,0 +1,80 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2012 Bhaskar Maddala
+ * Copyright (C) 2005-2012 Dave Brosius
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.mebigfatguy.fbcontrib.detect;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.JavaClass;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.ba.ClassContext;
+import edu.umd.cs.findbugs.bcel.OpcodeStackDetector;
+
+/**
+ * Detects use of Backport concurrent classes. Updated/Efficient version of
+ * these classes are available in versions of the JDK 5.0 and higher, and these
+ * classes should only be used if you are targeting JDK 1.4 and lower.
+ *
+ * Finds usage of classes from backport utils package.
+ */
+public class BackportReusePublicIdentifiers extends OpcodeStackDetector {
+
+ private final BugReporter bugReporter;
+
+ public BackportReusePublicIdentifiers(final BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ @Override
+ public void visitClassContext(ClassContext classContext) {
+ JavaClass cls = classContext.getJavaClass();
+ if (cls.getMajor() >= Constants.MAJOR_1_5) {
+ super.visitClassContext(classContext);
+ }
+ }
+
+ @Override
+ public void sawOpcode(int seen) {
+ switch (seen) {
+ case INVOKESTATIC: {
+ String className = getClassConstantOperand();
+ if (className.startsWith("edu/emory/mathcs/backport/")) {
+ reportBug();
+ }
+ }
+ break;
+ case INVOKESPECIAL: {
+ String className = getClassConstantOperand();
+ String methodName = getNameConstantOperand();
+ if (className.startsWith("edu/emory/mathcs/backport/")
+ && methodName.equals("<init>")) {
+ reportBug();
+ }
+ }
+ break;
+ }
+ }
+
+ private void reportBug() {
+ bugReporter.reportBug(new BugInstance(this,
+ "BRPI_BACKPORT_REUSE_PUBLIC_IDENTIFIERS", NORMAL_PRIORITY)
+ .addClass(this).addMethod(this).addSourceLine(this));
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BackportReusePublicIdentifiers.java
___________________________________________________________________
Added: svn-eol-style
+ native
Added: svn:mime-type
+ text/plain
Added: eol-style
+ native
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java 2012-02-02 18:00:41 UTC (rev 1711)
@@ -0,0 +1,171 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2012 Bhaskar Maddala
+ * Copyright (C) 2005-2012 Dave Brosius
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.mebigfatguy.fbcontrib.detect;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+
+import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.LocalVariable;
+import org.apache.bcel.classfile.LocalVariableTable;
+
+import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.OpcodeStack.Item;
+import edu.umd.cs.findbugs.bcel.OpcodeStackDetector;
+
+/**
+ * Find usage of ToStringBuilder from Apache commons, where the code invokes
+ * toString() on the constructed object without invoking append().
+ *
+ * Usage without invoking append is equivalent of using the Object.toString()
+ * method
+ *
+ * <pre>
+ * new ToStringBuilder(this).toString();
+ * </pre>
+ */
+public class CommonsStringBuilderToString extends OpcodeStackDetector {
+
+ private final BugReporter bugReporter;
+ private Stack<Pair> stackTracker = new Stack<Pair>();
+ private Map<Integer, Boolean> registerTracker = new HashMap<Integer, Boolean>();
+
+ /**
+ * constructs a CSBTS detector given the reporter to report bugs on.
+ *
+ * @param bugReporter
+ * the sync of bug reports
+ */
+ public CommonsStringBuilderToString(final BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ @Override
+ public void visit(Code obj) {
+ registerTracker.clear();
+ stackTracker.clear();
+ super.visit(obj);
+ }
+
+ @Override
+ public boolean shouldVisitCode(Code obj) {
+ LocalVariableTable lvt = getMethod().getLocalVariableTable();
+ return lvt != null;
+ }
+
+ @Override
+ public void sawOpcode(int seen) {
+ switch (seen) {
+ case ALOAD:
+ case ALOAD_0:
+ case ALOAD_1:
+ case ALOAD_2:
+ case ALOAD_3:
+ LocalVariable lv = getMethod().getLocalVariableTable()
+ .getLocalVariable(RegisterUtils.getALoadReg(this, seen),
+ getNextPC());
+ if (lv != null) {
+ String signature = lv.getSignature();
+ if (isToStringBuilder(signature)) {
+ Integer loadReg = Integer.valueOf(getRegisterOperand());
+ Boolean appendInvoked = registerTracker.get(loadReg);
+ if (appendInvoked != null) {
+ stackTracker.add(new Pair(loadReg.intValue(),
+ appendInvoked.booleanValue()));
+ }
+ }
+ }
+ break;
+ case ASTORE:
+ case ASTORE_0:
+ case ASTORE_1:
+ case ASTORE_2:
+ case ASTORE_3:
+ Item si = stack.getStackItem(0);
+ String signature = si.getSignature();
+ if (isToStringBuilder(signature)) {
+ int storeReg = getRegisterOperand();
+ Pair p = stackTracker.pop();
+ registerTracker.put(
+ Integer.valueOf(storeReg),
+ p.register == -1 ? Boolean.FALSE : registerTracker
+ .get(Integer.valueOf(p.register)));
+ }
+ break;
+ case POP:
+ si = stack.getStackItem(0);
+ signature = si.getSignature();
+ if (isToStringBuilder(signature)) {
+ Pair p = stackTracker.pop();
+ registerTracker.put(Integer.valueOf(p.register),
+ Boolean.valueOf(p.appendInvoked));
+ }
+ break;
+ case INVOKESPECIAL:
+ case INVOKEVIRTUAL:
+ String loadClassName = getClassConstantOperand();
+ String calledMethodName = getNameConstantOperand();
+ String calledMethodSig = getSigConstantOperand();
+
+ if ("org/apache/commons/lang3/builder/ToStringBuilder"
+ .equals(loadClassName)
+ || "org/apache/commons/lang/builder/ToStringBuilder"
+ .equals(loadClassName)) {
+ if ("<init>".equals(calledMethodName)
+ && "(Ljava/lang/Object;)V".equals(calledMethodSig)) {
+ stackTracker.add(new Pair(-1, false));
+ } else if ("append".equals(calledMethodName)) {
+ Pair p = stackTracker.pop();
+ stackTracker.add(new Pair(p.register, true));
+ } else if ("toString".equals(calledMethodName)
+ && "()Ljava/lang/String;".equals(calledMethodSig)) {
+ Pair p = stackTracker.pop();
+ if (p.appendInvoked == false) {
+ bugReporter.reportBug(new BugInstance(this,
+ "CSBTS_COMMONS_STRING_BUILDER_TOSTRING",
+ HIGH_PRIORITY).addClass(this).addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ }
+ }
+
+ private boolean isToStringBuilder(String signature) {
+ return "Lorg/apache/commons/lang3/builder/ToStringBuilder;"
+ .equals(signature)
+ || "Lorg/apache/commons/lang/builder/ToStringBuilder;"
+ .equals(signature);
+ }
+
+ static final class Pair {
+ public final int register;
+ public final boolean appendInvoked;
+
+ Pair(int register, boolean appendInvoked) {
+ this.register = register;
+ this.appendInvoked = appendInvoked;
+ }
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java
___________________________________________________________________
Added: svn-eol-style
+ native
Added: svn:mime-type
+ text/plain
Added: eol-style
+ native
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CompareClassNameEquals.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CompareClassNameEquals.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CompareClassNameEquals.java 2012-02-02 18:00:41 UTC (rev 1711)
@@ -0,0 +1,90 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2012 Bhaskar Maddala
+ * Copyright (C) 2005-2012 Dave Brosius
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.mebigfatguy.fbcontrib.detect;
+
+import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.LocalVariableTable;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.OpcodeStack.Item;
+import edu.umd.cs.findbugs.bcel.OpcodeStackDetector;
+
+/**
+ * In a JVM, Two classes are the same class (and consequently the same type) if
+ * they are loaded by the same class loader, and they have the same fully
+ * qualified name [JVMSpec 1999].
+ *
+ * Two classes with the same name but different package names are distinct, as
+ * are two classes with the same fully qualified name loaded by different class
+ * loaders.
+ *
+ * Find usage involving comparison of class names, rather than the class itself.
+ *
+ */
+public class CompareClassNameEquals extends OpcodeStackDetector {
+ private boolean flag = false;
+ private final BugReporter bugReporter;
+
+ public CompareClassNameEquals(final BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ @Override
+ public boolean shouldVisitCode(Code obj) {
+ flag = false;
+ LocalVariableTable lvt = getMethod().getLocalVariableTable();
+ return lvt != null;
+ }
+
+ @Override
+ public void afterOpcode(int seen) {
+ super.afterOpcode(seen);
+ if (flag == true) {
+ stack.getStackItem(0).setUserValue(Boolean.TRUE);
+ flag = false;
+ }
+ }
+
+ @Override
+ public void sawOpcode(int seen) {
+ switch (seen) {
+ case INVOKEVIRTUAL:
+ if ("getName".equals(getNameConstantOperand())
+ && "()Ljava/lang/String;".equals(getSigConstantOperand())
+ && "java/lang/Class".equals(getClassConstantOperand())) {
+ flag = true;
+ } else if ("equals".equals(getNameConstantOperand())
+ && "(Ljava/lang/Object;)Z".equals(getSigConstantOperand())
+ && "java/lang/String".equals(getClassConstantOperand())) {
+ Item item = stack.getItemMethodInvokedOn(this);
+ Object userValue = item.getUserValue();
+ if (userValue != null && userValue == Boolean.TRUE) {
+ bugReporter
+ .reportBug(new BugInstance(this,
+ "CCNE_COMPARE_CLASS_EQUALS_NAME",
+ NORMAL_PRIORITY).addClass(this)
+ .addMethod(this).addSourceLine(this));
+ }
+ }
+ break;
+ }
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CompareClassNameEquals.java
___________________________________________________________________
Added: svn-eol-style
+ native
Added: svn:mime-type
+ text/plain
Added: eol-style
+ native
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|