[Fb-contrib-commit] SF.net SVN: fb-contrib:[1778] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2015-05-26 03:14:31
|
Revision: 1778
http://sourceforge.net/p/fb-contrib/code/1778
Author: dbrosius
Date: 2015-05-26 03:14:28 +0000 (Tue, 26 May 2015)
Log Message:
-----------
sync from github
Modified Paths:
--------------
trunk/fb-contrib/build.xml
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/htdocs/index.shtml
trunk/fb-contrib/pom.xml
trunk/fb-contrib/samples/BAS_Sample.java
trunk/fb-contrib/samples/LO_Sample.java
trunk/fb-contrib/samples/NAB_Sample.java
trunk/fb-contrib/samples/PRMC_Sample.java
trunk/fb-contrib/samples/WOC_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractOverriddenMethod.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayIndexOutOfBounds.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MethodReturnsConstant.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MissingMethodsDetector.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessCustomSerialization.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyPermissiveMethod.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleIncompleteSerialization.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PresizeCollections.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousLoopSearch.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/ToString.java
Modified: trunk/fb-contrib/build.xml
===================================================================
--- trunk/fb-contrib/build.xml 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/build.xml 2015-05-26 03:14:28 UTC (rev 1778)
@@ -18,7 +18,7 @@
<property name="javac.deprecation" value="on" />
<property name="javac.debug" value="on" />
- <property name="fb-contrib.version" value="6.0.1" />
+ <property name="fb-contrib.version" value="6.1.0" />
<property name="sonatype.dir" value="${user.home}/.fb-contrib-${fb-contrib.version}-sonatype" />
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/etc/findbugs.xml 2015-05-26 03:14:28 UTC (rev 1778)
@@ -20,7 +20,7 @@
<!-- Detectors -->
-<!-- COMMENT OUT FOR RELEASE
+<!-- COMMENT OUT FOR RELEASE -->
<Detector class="com.mebigfatguy.fbcontrib.debug.OCSDebugger" speed="fast"/>
@@ -34,7 +34,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" reports="BAS_BLOATED_ASSIGNMENT_SCOPE" hidden="true" />
- COMMENT OUT FOR RELEASE -->
+<!-- COMMENT OUT FOR RELEASE -->
<Detector class="com.mebigfatguy.fbcontrib.collect.CollectStatistics" speed="fast" reports="" hidden="true" />
@@ -277,7 +277,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.ConflictingTimeUnits" speed="fast" reports="CTU_CONFLICTING_TIME_UNITS" />
- <!-- COMMENT OUT FOR POINT RELEASE
+ <!-- COMMENT OUT FOR POINT RELEASE -->
<Detector class="com.mebigfatguy.fbcontrib.detect.CharsetIssues" speed="fast" reports="CSI_CHAR_SET_ISSUES_USE_STANDARD_CHARSET,CSI_CHAR_SET_ISSUES_UNKNOWN_ENCODING,CSI_CHAR_SET_ISSUES_USE_STANDARD_CHARSET_NAME" />
@@ -291,7 +291,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.ConflatingResourcesAndFiles" speed="fast" reports="CRF_CONFLATING_RESOURCES_AND_FILES" />
- COMMENT OUT FOR POINT RELEASE -->
+ <!-- COMMENT OUT FOR POINT RELEASE -->
<!-- BugPattern -->
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/etc/messages.xml 2015-05-26 03:14:28 UTC (rev 1778)
@@ -40,6 +40,10 @@
sb.append(a + b);
return sb.toString();
</pre>
+ You should use the .append method to append values
+ <pre>
+ sb.append(a).append(b);
+ </pre>
<p>It is a fast detector.</p>
]]>
</Details>
@@ -2863,8 +2867,8 @@
</BugPattern>
<BugPattern type="SPP_STRINGBUFFER_WITH_EMPTY_STRING">
- <ShortDescription>Method passes empty string to StringBuffer of StringBuilder constructor</ShortDescription>
- <LongDescription>Method {1} passes empty string to StringBuffer of StringBuilder constructor</LongDescription>
+ <ShortDescription>Method passes an empty string to StringBuffer of StringBuilder constructor</ShortDescription>
+ <LongDescription>Method {1} passes an empty string to StringBuffer of StringBuilder constructor</LongDescription>
<Details>
<![CDATA[
<p>This method calls the StringBuffer or StringBuilder constructor passing in a constant empty string ("").
Modified: trunk/fb-contrib/htdocs/index.shtml
===================================================================
--- trunk/fb-contrib/htdocs/index.shtml 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/htdocs/index.shtml 2015-05-26 03:14:28 UTC (rev 1778)
@@ -68,9 +68,12 @@
</li>
</ul>
</p>
- <p style="font-weight: bold;">The latest version of fb-contrib is 6.0.0 available for download
- <a href="http://sourceforge.net/projects/fb-contrib/files/Current/fb-contrib-6.0.0.jar/download">here</a>.</p>
- <p style="font-weight: bold;">This version requires FindBugs 3.0 or better</p>
+ <p style="font-weight: bold;">The latest version of fb-contrib is 6.0.1 available for download
+ <a href="http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22fb-contrib%22">here</a>.</p>
+ <p style="font-weight: bold;">This version requires FindBugs 3.0.1 or better</p>
+ <p style="font-weight: bold;">Please note that active development for this project is now done on
+ github. If this site seems behind, please <a href="http://github.com/mebigfatguy/fb-contrib">check there</a>.
+ I will try to keep this site up to date, but I'd appreciate a poke if you see something missing.</p>
</div>
<hr/>
@@ -98,6 +101,15 @@
Looks for string fields that appear to be built with parsing or calling
toString() on another object, or from objects that are fields.
</li>
+ <li><b>[SLS] Suspicious Loop Search</b><br/>
+ Looks for loops where an equality check is made and a variable is set because of it.
+ It would seem once the item is found, the loop can be terminated, but is not.
+ </li>
+ <li><b>[CRF] Conflating Resources and Files</b><br/>
+ Looks for code that uses the File api on URI/URLs where the reference is not a file based one.
+ In the case of classpath URIs, this may work if the classpath is resolving to a folder, but will
+ fall for jar files.
+ </li>
</ul>
</div>
Modified: trunk/fb-contrib/pom.xml
===================================================================
--- trunk/fb-contrib/pom.xml 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/pom.xml 2015-05-26 03:14:28 UTC (rev 1778)
@@ -8,7 +8,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
- <version>6.0.1</version>
+ <version>6.1.0</version>
<parent>
<groupId>org.sonatype.oss</groupId>
Modified: trunk/fb-contrib/samples/BAS_Sample.java
===================================================================
--- trunk/fb-contrib/samples/BAS_Sample.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/samples/BAS_Sample.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -165,6 +165,21 @@
return null;
}
+
+ public void testFPNestedIfs(Map<String, String> x, int i, boolean b) {
+
+ String s = x.get("hello");
+
+ if (i == 0) {
+ if (b) {
+ System.out.println(s);
+ }
+ } else if (i == 1) {
+ System.out.println(s);
+ } else if (i == 2) {
+ System.out.println(s);
+ }
+ }
static class Holder {
int member;
Modified: trunk/fb-contrib/samples/LO_Sample.java
===================================================================
--- trunk/fb-contrib/samples/LO_Sample.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/samples/LO_Sample.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -20,6 +20,8 @@
private static Logger l4 = Logger.getLogger(ActionEvent.class.getName());
//no tag
private static Logger l5 = Logger.getLogger(LO_Sample.class.getName());
+ //no tag
+ private static Logger l6 = Logger.getLogger("my.nasty.logger.LOGGER");
//no tag
private Logger someLocalLogger;
Modified: trunk/fb-contrib/samples/NAB_Sample.java
===================================================================
--- trunk/fb-contrib/samples/NAB_Sample.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/samples/NAB_Sample.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -128,4 +128,9 @@
public Boolean testBooleanReturns() {
return true;
}
+
+ public Integer testfpTernary(Integer i, int[] data) {
+ Integer j = (i == null) ? data.length : i;
+ return j;
+ }
}
Modified: trunk/fb-contrib/samples/PRMC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/PRMC_Sample.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/samples/PRMC_Sample.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -1,4 +1,5 @@
import java.nio.ByteBuffer;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
@@ -41,6 +42,11 @@
Factory.getInstance().fo();
Factory.getInstance().fum();
}
+
+ public void repeatedEmptyArrays() {
+ System.out.println(Arrays.asList(new Integer[0]));
+ System.out.println(Arrays.asList(new Integer[0]));
+ }
static class Factory {
private static Factory f = new Factory();
@@ -106,6 +112,11 @@
SAMPLE2 = new PRMC_Sample();
SAMPLE2.setValue(5);
}
+
+ public void fpAsListLiterals() {
+ System.out.println(Arrays.asList("foo"));
+ System.out.println(Arrays.asList("bar"));
+ }
public void setValue(int i) {
}
Modified: trunk/fb-contrib/samples/WOC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/WOC_Sample.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/samples/WOC_Sample.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -1,5 +1,6 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -18,6 +19,11 @@
private final List<String> fpList = new ArrayList<String>();
private List<String> fp1 = new ArrayList<String>();
private List<String> fp2 = new ArrayList<String>();
+ private List<String> fp3;
+
+ public WOC_Sample(List<String> x) {
+ fp3 = x;
+ }
public void testWOCSimple() {
//tag WOC_WRITE_ONLY_COLLECTION_LOCAL
@@ -141,6 +147,13 @@
}
l.add("Hello there");
}
+
+ public void fpClone(List<Data> l) {
+ HashSet<String> s = new HashSet<>();
+ for (Data d : l) {
+ d.ss = (Set<String>) s.clone();
+ }
+ }
public static class FpContains {
private List<String> fpSetList;
@@ -161,4 +174,12 @@
}
}
}
+
+ public void fpAddToCtorParm(String x) {
+ fp3.add(x);
+ }
+
+ private class Data {
+ Set<String> ss;
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractOverriddenMethod.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractOverriddenMethod.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractOverriddenMethod.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -102,9 +102,10 @@
}
/**
- * implements the Detector with a nop
+ * implements the Detector with a noop
*/
@Override
public void report() {
+ //not used, part of the Detector interface
}
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayIndexOutOfBounds.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayIndexOutOfBounds.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayIndexOutOfBounds.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -139,7 +139,7 @@
case BIPUSH:
case SIPUSH:
- size = getIntConstant();
+ size = Integer.valueOf(getIntConstant());
sizeSet = true;
break;
@@ -212,7 +212,7 @@
int reg = arrayItem.getRegisterNumber();
if ((reg >= 0) && !initializedRegs.get(reg)) {
- nullStoreToLocation.put(Integer.valueOf(reg), getPC());
+ nullStoreToLocation.put(Integer.valueOf(reg), Integer.valueOf(getPC()));
}
}
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -298,8 +298,6 @@
rootScopeBlock.addChild(sb);
} else {
sb.pushUpLoadStores();
- sb.setStart(pc);
- sb.setFinish(target);
}
} else {
sb = new ScopeBlock(pc, target);
@@ -370,7 +368,7 @@
rootScopeBlock.addChild(sb);
} else if (seen == MONITOREXIT) {
if (monitorSyncPCs.size() > 0) {
- ScopeBlock sb = findSynchronizedScopeBlock(rootScopeBlock, monitorSyncPCs.get(0));
+ ScopeBlock sb = findSynchronizedScopeBlock(rootScopeBlock, monitorSyncPCs.get(0).intValue());
if (sb != null)
sb.setFinish(pc);
monitorSyncPCs.remove(monitorSyncPCs.size() - 1);
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -249,5 +249,6 @@
*/
@Override
public void report() {
+ // not used, supplied to support the Detector interface
}
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -81,6 +81,7 @@
*/
@Override
public void report() {
+ // not used, required by the Detector interface
}
/**
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -80,6 +80,7 @@
exceptionClasses.add(Repository.lookupClass("java/util/concurrent/CopyOnWriteArrayList"));
exceptionClasses.add(Repository.lookupClass("java/util/concurrent/CopyOnWriteArraySet"));
} catch (ClassNotFoundException cnfe) {
+ //don't have a bugReporter yet, so do nothing
}
collectionMethods = new HashSet<String>(3);
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -46,6 +46,7 @@
setCls = Repository.lookupClass("java/util/Set");
mapCls = Repository.lookupClass("java/util/Map");
} catch (ClassNotFoundException cnfe) {
+ // np bugReporter yet, so ignore
}
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -370,6 +370,7 @@
if (loggingClassName != null) {
//first look at the constant passed in
loggingClassName = loggingClassName.replace('.', '/');
+ loggingPriority = LOW_PRIORITY;
} else if (userValue instanceof String){
//try the user value, which may have been set by a call to Foo.class.getName()
loggingClassName = (String) userValue;
@@ -383,6 +384,7 @@
if (loggingClassName != null) {
loggingClassName = loggingClassName.replace('.', '/');
}
+ loggingPriority = LOW_PRIORITY;
}
}
} else if ("org/apache/commons/logging/LogFactory".equals(callingClsName) && "getLog".equals(mthName)) {
@@ -400,6 +402,7 @@
if (loggingClassName != null) {
loggingClassName = loggingClassName.replace('.', '/');
}
+ loggingPriority = LOW_PRIORITY;
}
}
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MethodReturnsConstant.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MethodReturnsConstant.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MethodReturnsConstant.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -121,7 +121,7 @@
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
- int register = item.getRegisterNumber();
+ Integer register = Integer.valueOf(item.getRegisterNumber());
if (registerConstants.containsKey(register) && (registerConstants.get(register) == null)) {
methodSuspect = false;
return;
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MissingMethodsDetector.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MissingMethodsDetector.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MissingMethodsDetector.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -360,6 +360,10 @@
item.setUserValue(null);
}
+ protected OpcodeStack getStack() {
+ return stack;
+ }
+
/**
* Checks to see if any of the locals or fields that we are tracking are passed into
* another method. If they are, we clear out our tracking of them, because we can't
@@ -378,6 +382,13 @@
}
}
+
+ /**
+ * informs the missing method detector that a field should no longer be considered special
+ */
+ protected void clearSpecialField(String name) {
+ fieldSpecialObjects.remove(name);
+ }
protected abstract BugInstance makeFieldBugInstance();
protected abstract BugInstance makeLocalBugInstance();
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -18,6 +18,7 @@
*/
package com.mebigfatguy.fbcontrib.detect;
+import java.util.BitSet;
import java.util.HashMap;
import java.util.Map;
@@ -29,15 +30,16 @@
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;
+import edu.umd.cs.findbugs.bcel.OpcodeStackDetector;
/**
* Looks for methods that pass a primitive wrapper class object, to the
* same classes Constructor.
*/
-public class NeedlessAutoboxing extends BytecodeScanningDetector
+public class NeedlessAutoboxing extends OpcodeStackDetector
{
- enum State {SEEN_NOTHING, SEEN_VALUE, SEEN_VALUEOFSTRING, SEEN_PARSE, SEEN_CTOR, SEEN_VALUEOFPRIMITIVE, SEEN_GOTO, SEEN_ICONST, SEEN_GETSTATIC}
+ enum State {SEEN_NOTHING, SEEN_VALUE, SEEN_VALUEOFSTRING, SEEN_PARSE, SEEN_CTOR, SEEN_VALUEOFPRIMITIVE, SEEN_ICONST, SEEN_GETSTATIC}
private static final Map<String, String[]> boxClasses = new HashMap<String, String[]>();
static {
@@ -65,6 +67,7 @@
private BugReporter bugReporter;
private State state;
private String boxClass;
+ private BitSet ternaryPCs;
/**
* constructs a NAB detector given the reporter to report bugs on
@@ -73,18 +76,33 @@
public NeedlessAutoboxing(BugReporter bugReporter) {
this.bugReporter = bugReporter;
}
-
+
@Override
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ ternaryPCs = new BitSet();
+ super.visitClassContext(classContext);
+ } finally {
+ ternaryPCs = null;
+ }
+ }
+ @Override
public void visitMethod(Method obj) {
state = State.SEEN_NOTHING;
+ ternaryPCs.clear();
}
@Override
public void sawOpcode(int seen) {
+ if (ternaryPCs.get(getPC())) {
+ ternaryPCs.clear(getPC());
+ state = State.SEEN_NOTHING;
+ return;
+ }
+
switch (state) {
case SEEN_NOTHING:
- case SEEN_GOTO:
if (seen == INVOKEVIRTUAL) {
boxClass = getClassConstantOperand();
String[] boxSigs = boxClasses.get(boxClass);
@@ -135,7 +153,10 @@
state = State.SEEN_GETSTATIC;
}
} else if ((seen == GOTO) || (seen == GOTO_W)) {
- state = State.SEEN_GOTO;
+ if (stack.getStackDepth() > 0) {
+ ternaryPCs.set(getBranchTarget());
+ }
+ state = State.SEEN_NOTHING;
}
break;
@@ -254,6 +275,6 @@
state = State.SEEN_NOTHING;
sawOpcode(seen);
break;
- }
+ }
}
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessCustomSerialization.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessCustomSerialization.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessCustomSerialization.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -43,6 +43,7 @@
try {
serializableClass = Repository.lookupClass("java/io/Serializable");
} catch (ClassNotFoundException cnfe) {
+ // no bugReporter here, so do nothing
}
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyPermissiveMethod.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyPermissiveMethod.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyPermissiveMethod.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -254,7 +254,7 @@
}
private static String getDeclaredAccessValue(int declaredAccess) {
- return DECLARED_ACCESS.get(declaredAccess & (Constants.ACC_PRIVATE|Constants.ACC_PROTECTED|Constants.ACC_PUBLIC));
+ return DECLARED_ACCESS.get(Integer.valueOf(declaredAccess & (Constants.ACC_PRIVATE|Constants.ACC_PROTECTED|Constants.ACC_PUBLIC)));
}
private static Object getRequiredAccessValue(MethodInfo mi) {
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleIncompleteSerialization.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleIncompleteSerialization.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleIncompleteSerialization.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -66,14 +66,10 @@
}
}
}
-
}
} catch (ClassNotFoundException cnfe) {
-
- } finally {
-
+ bugReporter.reportMissingClass(cnfe);
}
-
}
/**
@@ -132,5 +128,6 @@
@Override
public void report() {
+ // Unused, requirement of the Detector interface
}
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -247,11 +247,14 @@
} else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE) || (seen == INVOKESTATIC)) {
String signature = getSigConstantOperand();
int parmCount = Type.getArgumentTypes(signature).length;
- int neededStackSize = parmCount - ((seen == INVOKESTATIC) ? 1 : 0);
+ int neededStackSize = parmCount - ((seen == INVOKESTATIC) ? 0 : 1);
if (stack.getStackDepth() > neededStackSize) {
Object[] parmConstants = new Object[parmCount];
for (int i = 0; i < parmCount; i++) {
OpcodeStack.Item parm = stack.getStackItem(i);
+ if ((parm.getSignature().charAt(0) == '[') && (!Values.ZERO.equals(parm.getConstant()))) {
+ return;
+ }
parmConstants[i] = parm.getConstant();
if (parmConstants[i] == null) {
return;
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PresizeCollections.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PresizeCollections.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PresizeCollections.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -113,7 +113,7 @@
bugReporter.reportBug(new BugInstance(this, BugType.PSC_PRESIZE_COLLECTIONS.name(), NORMAL_PRIORITY)
.addClass(this)
.addMethod(this)
- .addSourceLine(this, pcs.get(0)));
+ .addSourceLine(this, pcs.get(0).intValue()));
}
}
}
@@ -161,7 +161,7 @@
lines = new ArrayList<Integer>();
allocToAddPCs.put(allocNum, lines);
}
- lines.add(getPC());
+ lines.add(Integer.valueOf(getPC()));
}
}
}
@@ -180,7 +180,7 @@
lines = new ArrayList<Integer>();
allocToAddPCs.put(allocNum, lines);
}
- lines.add(getPC());
+ lines.add(Integer.valueOf(getPC()));
}
}
}
@@ -219,7 +219,7 @@
Integer allocLoc = allocLocation.get(entry.getKey());
if ((allocLoc != null) && (allocLoc.intValue() < target)) {
List<Integer> pcs = entry.getValue();
- for (Integer pc : pcs) {
+ for (int pc : pcs) {
if (pc > target) {
int numDownBranches = countDownBranches(target, pc);
if (numDownBranches == 1) {
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -697,7 +697,7 @@
Integer stackOffset = methodsThatAreSillyOnStringLiterals.get(methodName + signature);
if (stackOffset != null) {
- if (stack.getStackDepth() > stackOffset) {
+ if (stack.getStackDepth() > stackOffset.intValue()) {
OpcodeStack.Item itm = stack.getStackItem(stackOffset.intValue());
Object constant = itm.getConstant();
@@ -996,7 +996,7 @@
Object constant = item.getConstant();
if (constant instanceof Double)
{
- Double v = (Double) constant;
+ double v = ((Double) constant).doubleValue();
if ((v != 0.0) && (v != 1.0)) {
bugReporter.reportBug(new BugInstance(this, BugType.SPP_USE_BIGDECIMAL_STRING_CTOR.name(), NORMAL_PRIORITY)
.addClass(this)
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -105,6 +105,7 @@
*/
@Override
public void report() {
+ // Unused, requirement of the Detector interface
}
/**
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -47,6 +47,7 @@
compareClasses.put(Repository.lookupClass("java/lang/Comparable"), "compareTo:1:I");
compareClasses.put(Repository.lookupClass("java/util/Comparator"), "compare:2:I");
} catch (ClassNotFoundException cnfe) {
+ //don't have a bugReporter yet, so do nothing
}
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -228,6 +228,7 @@
try {
is.close();
} catch (IOException ioe) {
+ // don't care
}
}
}
@@ -302,7 +303,7 @@
return null;
}
- private static File getRTJarFromProperty(int requestedVersion) {
+ private static File getRTJarFromProperty(Integer requestedVersion) {
String jdkHome = System.getProperty(SJVU_JDKHOME + "." + HUMAN_VERSIONS.get(requestedVersion));
if (jdkHome == null)
return null;
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousLoopSearch.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousLoopSearch.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousLoopSearch.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -38,6 +38,12 @@
import edu.umd.cs.findbugs.ba.ClassContext;
+/**
+ * looks for loops where an equality check is made and a variable is set because of it.
+ * It would seem once the item is found, the loop can be terminated, however the code
+ * continues on, looking for more matches. It is possible the code is looking for the last
+ * match, but if this we case, a reverse iterator might be more effective.
+ */
public class SuspiciousLoopSearch extends BytecodeScanningDetector {
enum State {SAW_NOTHING, SAW_EQUALS, SAW_IFEQ, SAW_ASSIGNMENT };
@@ -135,7 +141,7 @@
bugReporter.reportBug(new BugInstance(this, BugType.SLS_SUSPICIOUS_LOOP_SEARCH.name(), NORMAL_PRIORITY)
.addClass(this)
.addMethod(this)
- .addSourceLine(this, storeRegs.values().iterator().next()));
+ .addSourceLine(this, storeRegs.values().iterator().next().intValue()));
}
}
storeRegs.clear();
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -50,10 +50,15 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedBlockingDeque;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.generic.Type;
+
import com.mebigfatguy.fbcontrib.utils.BugType;
+import com.mebigfatguy.fbcontrib.utils.SignatureUtils;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.OpcodeStack;
import edu.umd.cs.findbugs.OpcodeStack.CustomUserValue;
/**
@@ -109,7 +114,6 @@
nonInformationalMethods.add("addFirst");
nonInformationalMethods.add("addLast");
nonInformationalMethods.add("clear");
- nonInformationalMethods.add("clone");
nonInformationalMethods.add("ensureCapacity");
nonInformationalMethods.add("insertElementAt");
nonInformationalMethods.add("push");
@@ -125,6 +129,8 @@
nonInformationalMethods.add("setSize");
nonInformationalMethods.add("trimToSize");
}
+
+ private int firstLocalRegister;
/**
* constructs a WOC detector given the reporter to report bugs on
@@ -134,7 +140,35 @@
super(bugReporter);
}
+ /**
+ * overrides the visitor to see what how many register slots are taken by
+ * parameters.
+ *
+ * @param obj the currently parsed method
+ */
@Override
+ public void visitMethod(Method obj) {
+ Type[] parms = Type.getArgumentTypes(obj.getSignature());
+ firstLocalRegister = SignatureUtils.getFirstRegisterSlot(obj);
+ super.visitMethod(obj);
+ }
+
+ @Override
+ public void sawOpcode(int seen) {
+ if (seen == PUTFIELD) {
+ OpcodeStack stack = getStack();
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ int reg = item.getRegisterNumber();
+ if ((reg >= 0) && (reg < firstLocalRegister)) {
+ clearSpecialField(getNameConstantOperand());
+ }
+ }
+ }
+ super.sawOpcode(seen);
+ }
+
+ @Override
protected BugInstance makeFieldBugInstance() {
return new BugInstance(this, BugType.WOC_WRITE_ONLY_COLLECTION_FIELD.name(), NORMAL_PRIORITY);
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -180,7 +180,25 @@
return parmSigs;
}
+
+ /**
+ * returns the first open register slot after parameters
+ *
+ * @param m the method for which you want the parameters
+ * @return the first available register slot
+ */
+ public static int getFirstRegisterSlot(Method m) {
+ Type[] parms = m.getArgumentTypes();
+ int first = m.isStatic() ? 0 : 1;
+ for (Type t : parms) {
+ String signature = t.getSignature();
+ first += ("J".equals(signature) || "D".equals(signature)) ? 2 : 1;
+ }
+
+ return first;
+ }
+
public static boolean compareGenericSignature(String genericSignature, String regularSignature) {
Type[] regParms = Type.getArgumentTypes(regularSignature);
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/ToString.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/ToString.java 2015-05-06 00:39:22 UTC (rev 1777)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/ToString.java 2015-05-26 03:14:28 UTC (rev 1778)
@@ -59,7 +59,7 @@
StringBuilder sb = new StringBuilder(100);
Class<?> cls = o.getClass();
- int identityHC = System.identityHashCode(o);
+ Integer identityHC = Integer.valueOf(System.identityHashCode(o));
sb.append(cls.getSimpleName()).append('[').append(identityHC).append("]{");
if (!visitedObjects.contains(identityHC)) {
@@ -87,6 +87,7 @@
}
}
} catch (Exception e) {
+ // if we get an exception show as much as we can get
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|