[Fb-contrib-commit] SF.net SVN: fb-contrib:[1735] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2012-12-30 08:44:35
|
Revision: 1735
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1735&view=rev
Author: dbrosius
Date: 2012-12-30 08:44:25 +0000 (Sun, 30 Dec 2012)
Log Message:
-----------
sync from git
Modified Paths:
--------------
trunk/fb-contrib/build.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/pom.xml
trunk/fb-contrib/samples/BAS_Sample.java
trunk/fb-contrib/samples/CCNE_Sample.java
trunk/fb-contrib/samples/MRC_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsEqualsBuilderToEquals.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsHashcodeBuilderToHashcode.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CompareClassNameEquals.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java
Modified: trunk/fb-contrib/build.xml
===================================================================
--- trunk/fb-contrib/build.xml 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/build.xml 2012-12-30 08:44:25 UTC (rev 1735)
@@ -18,10 +18,13 @@
<property name="javac.debug" value="on" />
<property name="fb-contrib.version" value="4.9.0" />
+
+ <property name="sonatype.dir" value="${user.home}/.fb-contrib-${fb-contrib.version}-sonatype" />
+
- <property name="findbugs.version" value="2.0.0" />
- <property name="findbugs-bcel.version" value="2.0.0" />
- <property name="annotations.version" value="2.0.0" />
+ <property name="findbugs.version" value="2.0.1" />
+ <property name="findbugs-bcel.version" value="2.0.1" />
+ <property name="annotations.version" value="2.0.1" />
<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" />
@@ -221,4 +224,38 @@
<target name="release" depends="build, srczip, html, javadoc" description="prepares everything for a release" />
+ <target name="sonatype" depends="release" description="prepare an artifact bundle for sonatype">
+ <mkdir dir="${sonatype.dir}"/>
+ <copy todir="${sonatype.dir}" file="${basedir}/fb-contrib-${fb-contrib.version}.jar"/>
+ <copy tofile="${sonatype.dir}/fb-contrib-${fb-contrib.version}-sources.jar" file="${basedir}/fb-contrib-src-${fb-contrib.version}.zip"/>
+ <jar destfile="${sonatype.dir}/fb-contrib-${fb-contrib.version}-javadoc.jar" basedir="${basedir}" includes="javadoc/**"/>
+ <copy tofile="${sonatype.dir}/fb-contrib-${fb-contrib.version}.pom" file="${basedir}/pom.xml"/>
+
+ <exec executable="gpg">
+ <arg value="-abi" />
+ <arg value="${sonatype.dir}/fb-contrib-${fb-contrib.version}.jar" />
+ </exec>
+ <exec executable="gpg">
+ <arg value="-abi" />
+ <arg value="${sonatype.dir}/fb-contrib-${fb-contrib.version}.pom" />
+ </exec>
+ <exec executable="gpg">
+ <arg value="-abi" />
+ <arg value="${sonatype.dir}/fb-contrib-${fb-contrib.version}-sources.jar" />
+ </exec>
+ <exec executable="gpg">
+ <arg value="-abi" />
+ <arg value="${sonatype.dir}/fb-contrib-${fb-contrib.version}-javadoc.jar" />
+ </exec>
+ <jar destfile="${sonatype.dir}/bundle.jar" basedir="${sonatype.dir}" includes="fb-contrib*">
+ </jar>
+ <echo message="" />
+ <echo message="" />
+ <echo message="====================================================================================================================================" />
+ <echo message="sonatype update bundle produced at ${sonatype.dir}/bundle.jar" />
+ <echo message="upload this jar at https://oss.sonatype.org" />
+ <echo message="" />
+ <echo message="see link for details-> https://docs.sonatype.org/display/Repository/Uploading+3rd-party+Artifacts+to+The+Central+Repository" />
+ <echo message="====================================================================================================================================" />
+ </target>
</project>
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/etc/messages.xml 2012-12-30 08:44:25 UTC (rev 1735)
@@ -3577,7 +3577,7 @@
<BugCode abbrev="SMA">Stuttered Method Arguments</BugCode>
<BugCode abbrev="TBP">Tristate Boolean Pattern</BugCode>
<BugCode abbrev="SUA">Suspicious Uninitialized Array</BugCode>
- <BugCode abbrev="ITU">Inappropriate ToString Use</BugCode>
+ <BugCode abbrev="ITU">Inappropriate toString Use</BugCode>
<BugCode abbrev="IKNC">Inconsistent Key Name Casing</BugCode>
<BugCode abbrev="OC">Overzealous Casting</BugCode>
<BugCode abbrev="PDP">Poorly Defined Parameter</BugCode>
Modified: trunk/fb-contrib/pom.xml
===================================================================
--- trunk/fb-contrib/pom.xml 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/pom.xml 2012-12-30 08:44:25 UTC (rev 1735)
@@ -8,7 +8,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
- <version>4.7.0</version>
+ <version>4.9.0</version>
<parent>
<groupId>org.sonatype.oss</groupId>
@@ -91,7 +91,7 @@
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>findbugs</artifactId>
- <version>2.0.0</version>
+ <version>2.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
Modified: trunk/fb-contrib/samples/BAS_Sample.java
===================================================================
--- trunk/fb-contrib/samples/BAS_Sample.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/samples/BAS_Sample.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -1,5 +1,7 @@
import java.util.Calendar;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -151,4 +153,19 @@
System.out.println(delta);
}
}
+
+ public String testFPIteratorNext(Collection<String> c, boolean b) {
+ Iterator<String> it = c.iterator();
+
+ String s = it.next();
+
+ if (b) {
+ if (s == null) {
+ return "yay";
+ }
+ }
+
+ return it.next();
+
+ }
}
Modified: trunk/fb-contrib/samples/CCNE_Sample.java
===================================================================
--- trunk/fb-contrib/samples/CCNE_Sample.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/samples/CCNE_Sample.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -5,4 +5,11 @@
System.out.println(o.getClass().getName()
.equals(p.getClass().getName()));
}
+
+ public void fpCompareAgainstString(String name) {
+ Object o = new CCNE_Sample();
+
+ if (o.getClass().getName().equals(name))
+ System.out.println("booya");
+ }
}
Modified: trunk/fb-contrib/samples/MRC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/MRC_Sample.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/samples/MRC_Sample.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -1,3 +1,4 @@
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -3,19 +4,19 @@
@SuppressWarnings("all")
-public class MRC_Sample
+public class MRC_Sample
{
private int getValue() {
return 1;
}
-
+
private String getStringValue() {
return "Hello";
}
-
+
public float getFP()
{
return 0.0f;
}
-
+
private double getTwoValuesFP(boolean b)
{
@@ -25,23 +26,23 @@
else
return 0.0;
}
-
+
private String getTwoDupsBySwitch(int i)
{
switch (i)
{
case 1:
return "Hello";
-
+
case 2:
return "Hello";
-
+
default:
return "Hello";
}
}
-
-
+
+
private String fpStringBuilder()
{
StringBuilder sb = new StringBuilder();
@@ -49,12 +50,12 @@
return sb.toString();
}
-
+
private void fooIt(StringBuilder sb)
{
sb.append("Foo");
}
-
+
private int getCount(List<String> l)
{
int count = 0;
@@ -66,14 +67,24 @@
count += 1;
}
}
-
+
return count;
}
-
+
private int fpInc()
{
int i = 0;
i++;
return i;
}
+
+ private long fpCountChars(Collection<String> c)
+ {
+ long totLength = 0;
+ for (String s : c)
+ {
+ totLength += s.length();
+ }
+ return totLength;
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -1,17 +1,17 @@
/*
* fb-contrib - Auxiliary detectors for Java programs
* 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
@@ -41,7 +41,7 @@
private final BugReporter bugReporter;
private List<FinallyBlockInfo> fbInfo;
private int loadedReg;
-
+
/**
* constructs a AFBR detector given the reporter to report bugs on.
@@ -50,10 +50,10 @@
public AbnormalFinallyBlockReturn(final BugReporter bugReporter) {
this.bugReporter = bugReporter;
}
-
+
/**
* overrides the visitor to check for java class version being as good or better than 1.4
- *
+ *
* @param classContext the context object that holds the JavaClass parsed
*/
@Override
@@ -69,26 +69,26 @@
super.visitClassContext(classContext);
}
} finally {
- fbInfo = null;
+ fbInfo = null;
}
}
-
+
/**
* overrides the visitor to collect finally block info.
- *
+ *
* @param obj the code object to scan for finally blocks
*/
@Override
public void visitCode(Code obj) {
fbInfo.clear();
loadedReg = -1;
-
+
CodeException[] exc = obj.getExceptionTable();
if (exc != null) {
for (CodeException ce : exc) {
if ((ce.getCatchType() == 0)
&& (ce.getStartPC() == ce.getHandlerPC())) {
- fbInfo.add(new FinallyBlockInfo(ce.getStartPC(), ce.getEndPC()));
+ fbInfo.add(new FinallyBlockInfo(ce.getStartPC()));
}
}
}
@@ -96,22 +96,22 @@
if (!fbInfo.isEmpty())
super.visitCode(obj);
}
-
+
/**
* overrides the visitor to find return/exceptions from the finally block.
- *
+ *
* @param seen the opcode that is being visited
*/
@Override
public void sawOpcode(int seen) {
if (fbInfo.isEmpty())
return;
-
+
FinallyBlockInfo fbi = fbInfo.get(0);
-
+
if (getPC() < fbi.startPC)
return;
-
+
if (getPC() == fbi.startPC) {
if (seen == ASTORE)
fbi.exReg = getRegisterOperand();
@@ -124,7 +124,7 @@
}
return;
}
-
+
if (seen == MONITORENTER) {
fbi.monitorCount++;
} else if (seen == MONITOREXIT) {
@@ -135,11 +135,11 @@
return;
}
}
-
+
if ((seen == ATHROW) && (loadedReg == fbi.exReg)) {
fbInfo.remove(0);
sawOpcode(seen);
- return;
+ return;
}
else if (seen == ALOAD)
loadedReg = getRegisterOperand();
@@ -147,7 +147,7 @@
loadedReg = seen - ALOAD_0;
else
loadedReg = -1;
-
+
if (((seen >= IRETURN) && (seen <= RETURN)) || (seen == ATHROW)) {
bugReporter.reportBug(new BugInstance( this, "AFBR_ABNORMAL_FINALLY_BLOCK_RETURN", NORMAL_PRIORITY)
.addClass(this)
@@ -175,14 +175,14 @@
}
}
}
-
+
/**
* 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) {
@@ -192,26 +192,26 @@
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.
+ * 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 fBlockInfo the finally block the pc is currently in
- *
+ *
* @return if all exceptions are caught inside this finally block
*/
private boolean catchBlockInFinally(FinallyBlockInfo fBlockInfo) {
-
+
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)) {
@@ -220,29 +220,26 @@
}
}
}
-
+
return false;
}
-
+
/**
* holds the finally block information for a particular method.
*/
public static class FinallyBlockInfo
{
public int startPC;
- public int endPC;
public int monitorCount;
public int exReg;
-
+
/**
* create a finally block info for a specific code range
- *
+ *
* @param start the start of the try block
- * @param end the end of the try block
*/
- public FinallyBlockInfo(int start, int end) {
+ public FinallyBlockInfo(int start) {
startPC = start;
- endPC = end;
monitorCount = 0;
exReg = -1;
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -53,8 +53,9 @@
static {
dangerousAssignmentClassSources.add("java/io/InputStream");
dangerousAssignmentClassSources.add("java/io/ObjectInput");
- dangerousAssignmentMethodSources
- .add("java/lang/System.currentTimeMillis()J");
+ dangerousAssignmentMethodSources.add("java/lang/System.currentTimeMillis()J");
+ dangerousAssignmentMethodSources.add("java/util/Iterator.next()Ljava/lang/Object;");
+ dangerousAssignmentMethodSources.add("java/util/regex/Matcher.start()I");
}
BugReporter bugReporter;
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsEqualsBuilderToEquals.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsEqualsBuilderToEquals.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsEqualsBuilderToEquals.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -2,17 +2,17 @@
* 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
@@ -30,7 +30,7 @@
/**
* Find usage of EqualsBuilder from Apache commons, where the code invoke
* equals() on the constructed object rather than isEquals()
- *
+ *
* <pre>
* new EqualsBuilder().append(this.name, other.name).equals(other);
* </pre>
@@ -42,7 +42,7 @@
/**
* constructs a CEBE detector given the reporter to report bugs on.
- *
+ *
* @param bugReporter
* the sync of bug reports
*/
@@ -56,7 +56,7 @@
* initializers to the byte code scanning code. These methods are not
* reported, but are used to build SourceLineAnnotations for fields, if
* accessed.
- *
+ *
* @param obj
* the context object of the currently parsed code attribute
*/
@@ -76,8 +76,8 @@
case INVOKEVIRTUAL:
String methodName = getNameConstantOperand();
if ("equals".equals(methodName)
- && "(Ljava/lang/Object;)Z"
- .equals(getSigConstantOperand())) {
+ && "(Ljava/lang/Object;)Z".equals(getSigConstantOperand())
+ && (stack.getStackDepth() > 1)) {
String calledClass = stack.getStackItem(1).getSignature();
if ("Lorg/apache/commons/lang3/builder/EqualsBuilder;"
.equals(calledClass)
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsHashcodeBuilderToHashcode.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsHashcodeBuilderToHashcode.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsHashcodeBuilderToHashcode.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -2,17 +2,17 @@
* 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
@@ -30,7 +30,7 @@
/**
* Find usage of HashCodeBuilder from Apache commons, where the code invokes
* hashCode() on the constructed object rather than toHashCode()
- *
+ *
* <pre>
* new HashCodeBuilder().append(this.name).hashCode();
* </pre>
@@ -42,7 +42,7 @@
/**
* constructs a CHTH detector given the reporter to report bugs on.
- *
+ *
* @param bugReporter
* the sync of bug reports
*/
@@ -56,7 +56,7 @@
* initializers to the byte code scanning code. These methods are not
* reported, but are used to build SourceLineAnnotations for fields, if
* accessed.
- *
+ *
* @param obj
* the context object of the currently parsed code attribute
*/
@@ -76,7 +76,8 @@
case INVOKEVIRTUAL:
String methodName = getNameConstantOperand();
if ("hashCode".equals(methodName)
- && "()I".equals(getSigConstantOperand())) {
+ && "()I".equals(getSigConstantOperand())
+ && (stack.getStackDepth() > 0)) {
String calledClass = stack.getStackItem(0).getSignature();
if ("Lorg/apache/commons/lang3/builder/HashCodeBuilder;"
.equals(calledClass)
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -2,17 +2,17 @@
* 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
@@ -37,10 +37,10 @@
/**
* 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>
@@ -53,7 +53,7 @@
/**
* constructs a CSBTS detector given the reporter to report bugs on.
- *
+ *
* @param bugReporter
* the sync of bug reports
*/
@@ -126,12 +126,12 @@
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)) {
+ String calledMethodSig = getSigConstantOperand();
if ("<init>".equals(calledMethodName)
&& "(Ljava/lang/Object;)V".equals(calledMethodSig)) {
stackTracker.add(new Pair(-1, false));
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CompareClassNameEquals.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CompareClassNameEquals.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CompareClassNameEquals.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -75,8 +75,10 @@
&& "(Ljava/lang/Object;)Z".equals(getSigConstantOperand())
&& "java/lang/String".equals(getClassConstantOperand())) {
Item item = stack.getItemMethodInvokedOn(this);
- Object userValue = item.getUserValue();
- if (userValue != null && Boolean.TRUE.equals(userValue)) {
+ Object srcValue = item.getUserValue();
+ item = stack.getStackItem(0);
+ Object dstValue = item.getUserValue();
+ if (Boolean.TRUE.equals(srcValue) && Boolean.TRUE.equals(dstValue)) {
bugReporter
.reportBug(new BugInstance(this,
"CCNE_COMPARE_CLASS_EQUALS_NAME",
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -90,10 +90,10 @@
case ASTORE_3:
if(stack.getStackDepth() > 0){
OpcodeStack.Item item = stack.getStackItem(0);
- String sourceSignature = item.getSignature();
LocalVariable lv = getMethod().getLocalVariableTable()
.getLocalVariable(RegisterUtils.getAStoreReg(this, seen), getNextPC());
if(lv != null){
+ String sourceSignature = item.getSignature();
String targetSignature = lv.getSignature();
checkSignatures(sourceSignature, targetSignature);
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -1,17 +1,17 @@
/*
* fb-contrib - Auxiliary detectors for Java programs
* 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
@@ -34,7 +34,7 @@
/**
* looks for methods that build xml based strings by concatenation strings
- * and custom values together. Doing so makes brittle code, that is difficult to
+ * and custom values together. Doing so makes brittle code, that is difficult to
* modify, validate and understand. It is cleaner to create external xml files that are
* transformed at runtime, using parameters set through Transformer.setParameter.
*/
@@ -51,7 +51,7 @@
xmlPatterns.put(Pattern.compile("^[\"']>.*"), Boolean.TRUE);
xmlPatterns.put(Pattern.compile(".*<!\\[CDATA\\[.*", Pattern.CASE_INSENSITIVE), Boolean.TRUE);
xmlPatterns.put(Pattern.compile(".*\\]\\]>.*"), Boolean.TRUE);
- xmlPatterns.put(Pattern.compile(".*xmlns:.*"), Boolean.TRUE);
+ xmlPatterns.put(Pattern.compile(".*xmlns:.*"), Boolean.TRUE);
}
private static final String CBX_MIN_REPORTABLE_ITEMS = "fb-contrib.cbx.minxmlitems";
private BugReporter bugReporter;
@@ -62,7 +62,7 @@
private int midReportingThreshold;
private int highReportingThreshold;
private int firstPC;
-
+
/**
* constructs a CBX detector given the reporter to report bugs on
@@ -70,15 +70,15 @@
*/
public CustomBuiltXML(BugReporter bugReporter) {
this.bugReporter = bugReporter;
-
+
lowReportingThreshold = Integer.getInteger(CBX_MIN_REPORTABLE_ITEMS, 5).intValue();
midReportingThreshold = lowReportingThreshold << 1;
highReportingThreshold = lowReportingThreshold << 2;
}
-
+
/**
* overrides the visitor to create and destroy the stack
- *
+ *
* @param classContext the context object of the currently parsed class
*/
@Override
@@ -90,12 +90,12 @@
stack = null;
}
}
-
+
/**
* overrides the visitor reset the opcode stack
- *
+ *
* @param obj the code object of the currently parsed method
- */
+ */
@Override
public void visitCode(Code obj) {
stack.resetForMethodEntry(this);
@@ -103,7 +103,7 @@
xmlConfidentCount = 0;
firstPC = -1;
super.visitCode(obj);
- if ((xmlItemCount >= lowReportingThreshold)
+ if ((xmlItemCount >= lowReportingThreshold)
&& (xmlConfidentCount > (lowReportingThreshold >> 1))) {
bugReporter.reportBug( new BugInstance( this,
"CBX_CUSTOM_BUILT_XML",
@@ -113,22 +113,22 @@
.addClass(this)
.addMethod(this)
.addSourceLine(this, firstPC));
-
+
}
}
-
+
/**
* overrides the visitor to find String concatenations including xml strings
- *
+ *
* @param seen the opcode that is being visited
- */
+ */
@Override
public void sawOpcode(int seen) {
String strCon = null;
-
+
try {
stack.mergeJumps(this);
-
+
if (seen == INVOKESPECIAL) {
String clsName = getClassConstantOperand();
if ("java/lang/StringBuffer".equals(clsName) || "java/lang/StringBuilder".equals(clsName)) {
@@ -154,11 +154,12 @@
}
}
}
-
+
if (strCon != null) {
- if (strCon.trim().length() == 0)
+ strCon = strCon.trim();
+ if (strCon.length() == 0)
return;
-
+
for (Map.Entry<Pattern, Boolean> entry : xmlPatterns.entrySet()) {
Matcher m = entry.getKey().matcher(strCon);
if (m.matches()) {
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -1,17 +1,17 @@
/*
* fb-contrib - Auxiliary detectors for Java programs
* 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
@@ -51,14 +51,14 @@
private BugReporter bugReporter;
private OpcodeStack stack;
private Map<Integer, Integer> regPriorities;
-
+
/**
* constructs a NOS detector given the reporter to report bugs on
* @param bugReporter the sync of bug reports
*/ public NonOwnedSynchronization(BugReporter bugReporter) {
this.bugReporter = bugReporter;
}
-
+
/**
* implements the visitor to set and clear the stack and priorities
*/
@@ -73,10 +73,10 @@
regPriorities = null;
}
}
-
+
/**
* looks for methods that contain a MONITORENTER opcode
- *
+ *
* @param method the context object of the current method
* @return if the class uses synchronization
*/
@@ -84,10 +84,10 @@
BitSet bytecodeSet = getClassContext().getBytecodeSet(method);
return bytecodeSet != null && (bytecodeSet.get(Constants.MONITORENTER));
}
-
+
/**
* implements the visitor to reset the opcode stack
- *
+ *
* @param obj the context object of the currently parsed code block
*/
@Override
@@ -104,10 +104,10 @@
super.visitCode(obj);
}
}
-
+
/**
* implements the visitor to look for synchronization on non-owned objects
- *
+ *
* @param seen the opcode of the currently parsed instruction
*/
@Override
@@ -115,12 +115,12 @@
Integer tosIsPriority = null;
try {
stack.mergeJumps(this);
-
+
switch (seen) {
case GETFIELD:
tosIsPriority = OWNED;
break;
-
+
case ALOAD:
case ALOAD_0:
case ALOAD_1:
@@ -136,7 +136,7 @@
}
}
break;
-
+
case ASTORE:
case ASTORE_0:
case ASTORE_1:
@@ -149,14 +149,14 @@
}
}
break;
-
+
case INVOKEVIRTUAL:
case INVOKEINTERFACE: {
String sig = getSigConstantOperand();
Type t = Type.getReturnType(sig);
if (t.getSignature().startsWith("L")) {
int parmCnt = Type.getArgumentTypes(sig).length;
- if (stack.getStackDepth() >= parmCnt) {
+ if (stack.getStackDepth() > parmCnt) {
OpcodeStack.Item itm = stack.getStackItem(parmCnt);
Integer priority = (Integer)itm.getUserValue();
if ((priority != null) && OWNED.equals(priority)) {
@@ -172,7 +172,7 @@
}
}
break;
-
+
case INVOKESTATIC: {
String sig = getSigConstantOperand();
Type t = Type.getReturnType(sig);
@@ -180,7 +180,7 @@
tosIsPriority = OWNED; // can't be sure
}
break;
-
+
case INVOKESPECIAL: {
String name = getNameConstantOperand();
if ("<init>".equals(name)) {
@@ -188,7 +188,7 @@
}
}
break;
-
+
case MONITORENTER: {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item itm = stack.getStackItem(0);
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -1,17 +1,17 @@
/*
* fb-contrib - Auxiliary detectors for Java programs
* 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
@@ -67,16 +67,15 @@
}
private static final Pattern jarPattern = Pattern.compile("jar:file:/*([^!]*)");
private static final String SJVU_JDKHOME = "fb-contrib.sjvu.jdkhome";
-
+
private final Map<String, File> versionPaths;
private final Map<Integer, Map<String, Set<String>>> validMethodsByVersion;
private final Map<String, String> superNames;
private File jdksRoot = null;
private ZipFile jdkZip;
- private JavaClass cls;
private Integer clsMajorVersion;
- private final BugReporter bugReporter;
-
+ private final BugReporter bugReporter;
+
public SuspiciousJDKVersionUse(BugReporter bugReporter) {
this.bugReporter = bugReporter;
versionPaths = new HashMap<String, File>();
@@ -87,12 +86,11 @@
@Override
public void visitClassContext(ClassContext classContext) {
try {
- cls = classContext.getJavaClass();
- clsMajorVersion = Integer.valueOf(cls.getMajor());
+ clsMajorVersion = Integer.valueOf(classContext.getJavaClass().getMajor());
File rtJar = getRTJarFile();
if (rtJar == null)
rtJar = getRTJarFromProperty();
-
+
if (rtJar != null) {
jdkZip = new ZipFile(rtJar);
super.visitClassContext(classContext);
@@ -109,7 +107,6 @@
} catch (IOException ioe) {
//Hmm What to do
} finally {
- cls = null;
clsMajorVersion = null;
try {
if (jdkZip != null)
@@ -119,10 +116,10 @@
jdkZip = null;
}
}
-
+
@Override
public void sawOpcode(int seen) {
-
+
String clsName;
try {
if ((seen == INVOKEVIRTUAL) //Interfaces are more difficult, ignore for now
@@ -134,13 +131,13 @@
Method m = findCalledMethod();
if (m == null)
return;
-
+
Map<String, Set<String>> validMethods = validMethodsByVersion.get(clsMajorVersion);
if (validMethods == null) {
validMethods = new HashMap<String, Set<String>>();
validMethodsByVersion.put(clsMajorVersion, validMethods);
}
-
+
if (!isValid(validMethods, clsName)) {
bugReporter.reportBug(new BugInstance(this, "SJVU_SUSPICIOUS_JDK_VERSION_USE", HIGH_PRIORITY)
.addClass(this)
@@ -156,7 +153,7 @@
//Hmm what do do.
}
}
-
+
private Method findCalledMethod() {
try {
JavaClass clss = Repository.lookupClass(getClassConstantOperand());
@@ -168,7 +165,7 @@
return m;
}
}
-
+
return null;
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
@@ -178,23 +175,23 @@
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) {
-
+
ZipEntry ze = jdkZip.getEntry(clsName + ".class");
if (ze != null) {
is = new BufferedInputStream(jdkZip.getInputStream(ze));
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());
}
@@ -206,7 +203,7 @@
.addClass(clsName));
}
}
-
+
if (methodInfos != null) {
String wantedMethod = getNameConstantOperand() + getSigConstantOperand();
if (methodInfos.contains(wantedMethod))
@@ -216,7 +213,7 @@
else
return isValid(validMethods, superNames.get(clsName));
}
-
+
return true;
}
finally {
@@ -228,21 +225,21 @@
}
}
}
-
+
private File getRTJarFile(){
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);
@@ -252,10 +249,10 @@
jdksRoot = jdksRoot.getParentFile();
m = verPat.matcher(jdksRoot.getName());
}
-
+
if (jdksRoot.getParentFile() == null)
return null;
-
+
try {
String encoding = System.getProperty("file.encoding");
jdksRoot = new File(URLDecoder.decode(jdksRoot.getParentFile().getPath(), encoding));
@@ -265,7 +262,7 @@
}
}
}
-
+
if (jdksRoot != null) {
File[] possibleJdks = jdksRoot.listFiles();
for (File possibleJdk : possibleJdks) {
@@ -283,22 +280,22 @@
}
}
}
-
+
return null;
}
-
+
private File getRTJarFromProperty() {
String jdkHome = System.getProperty(SJVU_JDKHOME);
if (jdkHome == null)
return null;
-
+
File rtJar = new File(jdkHome, "lib/rt.jar");
if (rtJar.exists())
return rtJar;
rtJar = new File(jdkHome, "jre/lib/rt.jar");
if (rtJar.exists())
return rtJar;
-
+
return null;
}
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -1,17 +1,17 @@
/*
* fb-contrib - Auxiliary detectors for Java programs
* 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
@@ -40,11 +40,11 @@
* or variable is null.
*/
public class SuspiciousNullGuard extends BytecodeScanningDetector {
-
+
private final BugReporter bugReporter;
private OpcodeStack stack;
private Map<Integer, NullGuard> nullGuards;
-
+
/**
* constructs a SNG detector given the reporter to report bugs on
* @param bugReporter the sync of bug reports
@@ -52,10 +52,10 @@
public SuspiciousNullGuard(BugReporter bugReporter) {
this.bugReporter = bugReporter;
}
-
+
/**
* overrides the visitor to initialize and tear down the opcode stack
- *
+ *
* @param classContext the context object of the currently parsed class
*/
@Override
@@ -68,10 +68,10 @@
stack = null;
}
}
-
+
/**
* overrides the visitor to reset the stack
- *
+ *
* @param obj the context object of the currently parsed code block
*/
@Override
@@ -80,10 +80,10 @@
nullGuards.clear();
super.visitCode(obj);
}
-
+
/**
* overrides the visitor to look for bad null guards
- *
+ *
* @param seen the opcode of the currently visited instruction
*/
@Override
@@ -91,7 +91,7 @@
try {
Integer pc = Integer.valueOf(getPC());
nullGuards.remove(pc);
-
+
switch (seen) {
case IFNULL: {
if (stack.getStackDepth() > 0) {
@@ -109,7 +109,7 @@
}
}
break;
-
+
case ASTORE:
case ASTORE_0:
case ASTORE_1:
@@ -130,7 +130,7 @@
}
}
break;
-
+
case ALOAD:
case ALOAD_0:
case ALOAD_1:
@@ -142,7 +142,7 @@
}
}
break;
-
+
case PUTFIELD: {
if (stack.getStackDepth() > 1) {
OpcodeStack.Item item = stack.getStackItem(0);
@@ -162,7 +162,7 @@
}
}
break;
-
+
case GETFIELD: {
if (stack.getStackDepth() > 0) {
XField xf = getXFieldOperand();
@@ -175,7 +175,7 @@
}
}
break;
-
+
case IFEQ:
case IFNE:
case IFLT:
@@ -200,27 +200,27 @@
stack.sawOpcode(this, seen);
}
}
-
+
private NullGuard findNullGuardWithRegister(int reg) {
for (NullGuard guard : nullGuards.values()) {
if (guard.getRegister() == reg) {
return guard;
}
}
-
+
return null;
}
-
+
private NullGuard findNullGuardWithField(XField field) {
for (NullGuard guard : nullGuards.values()) {
if (field.equals(guard.getField())) {
return guard;
}
}
-
+
return null;
}
-
+
private void removeNullGuard(NullGuard guard) {
Iterator<NullGuard> it = nullGuards.values().iterator();
while (it.hasNext()) {
@@ -231,14 +231,13 @@
}
}
}
-
+
static class NullGuard {
int register;
XField field;
int location;
String signature;
- boolean sawSignature = false;
-
+
public NullGuard(int reg, int start, String guardSignature) {
register = reg;
field = null;
@@ -257,15 +256,15 @@
public int getRegister() {
return register;
}
-
+
public XField getField() {
return field;
}
-
+
public int getLocation() {
return location;
}
-
+
public String getSignature() {
return signature;
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -1,17 +1,17 @@
/*
* fb-contrib - Auxiliary detectors for Java programs
* 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
@@ -39,27 +39,26 @@
/**
* looks for methods that return Object, and who's code body returns two or more
- * different types of objects that are unrelated (other than by Object).
+ * different types of objects that are unrelated (other than by Object).
*/
-public class UnrelatedReturnValues extends BytecodeScanningDetector
+public class UnrelatedReturnValues extends BytecodeScanningDetector
{
private final BugReporter bugReporter;
private OpcodeStack stack;
private JavaClass currentClass;
private Map<JavaClass, Integer> returnTypes;
- private boolean isInherited;
-
+
/**
* constructs a URV detector given the reporter to report bugs on
* @param bugReporter the sync of bug reports
- */
+ */
public UnrelatedReturnValues(BugReporter bugReporter) {
this.bugReporter = bugReporter;
}
-
+
/**
* implements the visitor to create and destroy the stack and return types
- *
+ *
* @param classContext the context object of the currently parsed class
*/
@Override
@@ -79,7 +78,7 @@
/**
* implements the visitor to see if the method returns Object, and if the method
* is defined in a superclass, or interface.
- *
+ *
* @param obj the context object of the currently parsed code block
*/
@Override
@@ -89,7 +88,7 @@
String methodName = m.getName();
String signature = m.getSignature();
if (signature.endsWith(")Ljava/lang/Object;")) {
- isInherited = SignatureUtils.isInheritedMethod(currentClass, methodName, signature);
+ boolean isInherited = SignatureUtils.isInheritedMethod(currentClass, methodName, signature);
stack.resetForMethodEntry(this);
returnTypes.clear();
super.visitCode(obj);
@@ -101,7 +100,7 @@
break;
}
}
-
+
JavaClass cls = findCommonType(returnTypes.keySet());
BugInstance bug;
if ((cls != null) && !isInherited) {
@@ -112,11 +111,11 @@
} else if (!isInherited) {
bug = new BugInstance(this, "URV_UNRELATED_RETURN_VALUES", priority)
.addClass(this)
- .addMethod(this);
+ .addMethod(this);
} else {
bug = new BugInstance(this, "URV_INHERITED_METHOD_WITH_RELATED_TYPES", priority)
.addClass(this)
- .addMethod(this);
+ .addMethod(this);
if (cls != null)
bug.addString(cls.getClassName());
}
@@ -132,11 +131,11 @@
bugReporter.reportMissingClass(cnfe);
}
}
-
+
/**
- * implements the visitor to find return values where the types of objects returned from the
+ * implements the visitor to find return values where the types of objects returned from the
* method are related only by object.
- *
+ *
* @param seen the opcode of the currently parsed instruction
*/
@Override
@@ -156,10 +155,10 @@
stack.sawOpcode(this, seen);
}
}
-
+
/**
* looks for a common superclass or interface for all the passed in types
- *
+ *
* @param classes the set of classes to look for a common super class or interface
* @return the type that is the common interface or superclass (not Object, tho).
*/
@@ -170,10 +169,10 @@
for (JavaClass cls : classes) {
if (cls == null) //array
return null;
-
+
if ("java/lang/Object".equals(cls.getClassName()))
continue;
-
+
JavaClass[] infs = cls.getAllInterfaces();
JavaClass[] supers = cls.getSuperClasses();
if (populate) {
@@ -188,10 +187,10 @@
possibleCommonTypes.retainAll(retain);
}
}
-
+
if (possibleCommonTypes.isEmpty())
return null;
-
+
for (JavaClass cls : possibleCommonTypes) {
if (cls.isInterface())
return cls;
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java 2012-12-30 07:51:38 UTC (rev 1734)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java 2012-12-30 08:44:25 UTC (rev 1735)
@@ -1,17 +1,17 @@
/*
* fb-contrib - Auxiliary detectors for Java programs
* 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
@@ -39,23 +39,23 @@
import edu.umd.cs.findbugs.ba.ClassContext;
public class WeakExceptionMessaging extends BytecodeScanningDetector {
-
+
private static JavaClass exceptionClass;
private static final Set<String> ignorableExceptionTypes = new HashSet<String>();
-
+
static {
try {
exceptionClass = Repository.lookupClass("java/lang/Exception");
} catch (ClassNotFoundException cnfe) {
exceptionClass = null;
}
-
+
ignorableExceptionTypes.add("java.lang.UnsupportedOperationException");
}
-
+
private final BugReporter bugReporter;
private OpcodeStack stack;
-
+
/**
* constructs a WEM detector given the reporter to report bugs on
* @param bugReporter the sync of bug reports
@@ -63,10 +63,10 @@
public WeakExceptionMessaging(BugReporter bugReporter) {
this.bugReporter = bugReporter;
}
-
+
/**
* overrides the visitor to initialize and tear down the opcode stack
- *
+ *
* @param classContext the context object of the currently parsed class
*/
@Override
@@ -80,10 +80,10 @@
stack = null;
}
}
-
+
/**
* looks for methods that contain a ATHROW opcodes
- *
+ *
* @param method the context object of the current method
* @return if the class uses throws
*/
@@ -91,11 +91,11 @@
BitSet bytecodeSet = getClassContext().getBytecodeSet(method);
return (bytecodeSet != null) && (bytecodeSet.get(Constants.ATHROW));
}
-
+
/**
* overrides the visitor to prescreen the method to look for throws calls
* and only forward onto bytecode scanning if there
- *
+ *
* @param obj the context object of the currently parsed code block
*/
@Override
@@ -108,11 +108,11 @@
}
}
}
-
+
/**
* overrides the visitor to look for throws instructions using exceptions with
* static messages
- *
+ *
* @param seen the opcode of the currently visited instruction
*/
@Override
@@ -125,7 +125,7 @@
OpcodeStack.Item item = stack.getStackItem(0);
if (item.getUserValue() != null) {
JavaClass exClass = item.getJavaClass();
- if ((exClass == null) || !ignorableExceptionTypes.contains(item.getJavaClass().getClassName())) {
+ if ((exClass == null) || !ignorableExceptionTypes.contains(exClass.getClassName())) {
bugReporter.reportBug(new BugInstance(this, "WEM_WEAK_EXCEPTION_MESSAGING", LOW_PRIORITY)
.addClass(this)
.addMethod(this)
@@ -134,7 +134,7 @@
}
}
} else if ((seen == LDC) || (seen == LDC_W)) {
- if (getConstantRefOperand() instanceof ConstantString)
+ if (getConstantRefOperand() instanceof ConstantString)
sawConstant = true;
} else if (seen == INVOKESPECIAL) {
if ("<init>".equals(getNameConstantOperand())) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|