Permalink
Browse files

Merge branch 'findbugs' into spotbugs

 Conflicts:
	.classpath
  • Loading branch information...
mebigfatguy committed Nov 28, 2018
2 parents df6da39 + 2494f1d commit 3bcefd794a1acf514407068a41f3854faa7479dd
@@ -32,6 +32,7 @@
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="lib/log4j-api-2.9.1.jar"/>
<classpathentry kind="lib" path="lib/jsr305-3.0.2.jar"/>
<classpathentry kind="lib" path="lib/hamcrest-library-1.3.jar"/>
<classpathentry kind="lib" path="lib/spotbugs-3.1.0-RC3.jar"/>
<classpathentry kind="lib" path="lib/spotbugs-annotations-3.1.0-RC3.jar"/>
<classpathentry kind="lib" path="lib/spotbugs-ant-3.1.0-RC3.jar"/>
@@ -146,6 +146,7 @@
<pathelement location="${lib.dir}/jaxen-${jaxen.version}.jar" />
<pathelement location="${lib.dir}/mockito-core-${mockito-core.version}.jar" />
<pathelement location="${lib.dir}/hamcrest-core-${hamcrest-core.version}.jar" />
<pathelement location="${lib.dir}/hamcrest-library-${hamcrest-library.version}.jar" />
<pathelement location="${lib.dir}/jena-shaded-guava-${jena-shaded-guava.version}.jar" />
<pathelement location="${lib.dir}/javax.ws.rs-api-${javax.ws.rs-api.version}.jar" />
<pathelement location="${lib.dir}/jersey-media-multipart-${jersey-media-multipart.version}.jar" />
@@ -194,6 +194,7 @@
+0 BugPattern S508C_NULL_LAYOUT
+0 BugPattern S508C_SET_COMP_COLOR
+0 BugPattern SACM_STATIC_ARRAY_CREATED_IN_METHOD
+0 BugPattern SAT_SUSPICIOUS_ARGUMENT_TYPES
+0 BugPattern SCA_SUSPICIOUS_CLONE_ALGORITHM
+0 BugPattern SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR
+0 BugPattern SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTOR
@@ -333,6 +333,9 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.ClassEnvy" speed="slow" reports="CE_CLASS_ENVY" />
<!-- COMMENT OUT FOR POINT RELEASE -->
<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousArgumentTypes" speed="fast" reports="SAT_SUSPICIOUS_ARGUMENT_TYPES" />
<!-- COMMENT OUT FOR POINT RELEASE -->
<!-- BugPattern -->
@@ -639,4 +642,5 @@
<BugPattern abbrev="FII" type="FII_AVOID_SIZE_ON_COLLECTED_STREAM" category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="SUI" type="SUI_CONTAINS_BEFORE_ADD" category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="SUI" type="SUI_CONTAINS_BEFORE_REMOVE" category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="SAT" type="SAT_SUSPICIOUS_ARGUMENT_TYPES" category="CORRECTNESS" experimental="true" />
</FindbugsPlugin>
@@ -1756,6 +1756,16 @@ a[0] = new A(); // results in ArrayStoreException (Runtime)
]]>
</Details>
</Detector>
<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousArgumentTypes">
<Details>
<![CDATA[
<p>Looks for method calls where the arguments passed seem oddly typed for the use they are intended for.
</p>
<p>It is a fast detector</p>
]]>
</Details>
</Detector>
<Detector class="com.mebigfatguy.fbcontrib.debug.OCSDebugger">
<Details></Details>
@@ -6412,6 +6422,19 @@ if (shouldCalcHalting && (calculateHaltingProbability() &gt; 0) { }
</Details>
</BugPattern>
<BugPattern type="SAT_SUSPICIOUS_ARGUMENT_TYPES">
<ShortDescription>This method invokes a method with parameters that seem incorrect for their intended use</ShortDescription>
<LongDescription>This method {1} invokes a method with parameters that seem incorrect for their intended use</LongDescription>
<Details>
<![CDATA[
<p>This method calls a method passing arguments that seem incorrect for the intended purpose of the method. Make sure that the argument types are valid</p>
<ul>
<li><p>For Match.hasEntry it seems unlikely you want to pass a Matcher and non-Matcher at the same time</p></li>
</ul>
]]>
</Details>
</BugPattern>
<!-- BugCode -->
<BugCode abbrev="ISB">Inefficient String Buffering</BugCode>
@@ -6560,4 +6583,5 @@ if (shouldCalcHalting && (calculateHaltingProbability() &gt; 0) { }
<BugCode abbrev="LUI">List Usage Issues</BugCode>
<BugCode abbrev="FII">FunctionalInterface Issues</BugCode>
<BugCode abbrev="SUI">Set Usage Issues</BugCode>
<BugCode abbrev="SAT">Suspicious Argument Types</BugCode>
</MessageCollection>
@@ -0,0 +1,68 @@
package com.mebigfatguy.fbcontrib.detect;
import org.apache.bcel.Constants;
import org.apache.bcel.classfile.Code;
import com.mebigfatguy.fbcontrib.utils.BugType;
import com.mebigfatguy.fbcontrib.utils.FQMethod;
import com.mebigfatguy.fbcontrib.utils.SignatureBuilder;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
import edu.umd.cs.findbugs.OpcodeStack;
import edu.umd.cs.findbugs.ba.ClassContext;
public class SuspiciousArgumentTypes extends BytecodeScanningDetector {
private static final FQMethod HAS_ENTRY = new FQMethod("org/hamcrest/Matchers", "hasEntry", new SignatureBuilder()
.withParamTypes(Object.class, Object.class).withReturnType("Lorg/hamcrest/Matcher;").toString());
private static final String MATCHER_SIG = "Lorg/hamcrest/Matcher;";
private BugReporter bugReporter;
OpcodeStack stack;
public SuspiciousArgumentTypes(BugReporter bugReporter) {
this.bugReporter = bugReporter;
}
@Override
public void visitClassContext(ClassContext classContext) {
try {
stack = new OpcodeStack();
super.visitClassContext(classContext);
} finally {
stack = null;
}
}
@Override
public void visitCode(Code obj) {
stack.resetForMethodEntry(this);
super.visitCode(obj);
}
@Override
public void sawOpcode(int seen) {
try {
if (seen == Constants.INVOKESTATIC) {
FQMethod invokedMethod = new FQMethod(getClassConstantOperand(), getNameConstantOperand(),
getSigConstantOperand());
if (HAS_ENTRY.equals(invokedMethod)) {
if (stack.getStackDepth() >= 2) {
OpcodeStack.Item itm1 = stack.getStackItem(0);
OpcodeStack.Item itm2 = stack.getStackItem(1);
if (MATCHER_SIG.equals(itm1.getSignature()) || MATCHER_SIG.equals(itm2.getSignature())) {
bugReporter.reportBug(
new BugInstance(this, BugType.SAT_SUSPICIOUS_ARGUMENT_TYPES.name(), NORMAL_PRIORITY)
.addClass(this).addMethod(this).addSourceLine(this));
}
}
}
}
} finally {
stack.sawOpcode(this, seen);
}
}
}
@@ -233,6 +233,7 @@
S508C_NULL_LAYOUT,
S508C_SET_COMP_COLOR,
SACM_STATIC_ARRAY_CREATED_IN_METHOD,
SAT_SUSPICIOUS_ARGUMENT_TYPES,
SCA_SUSPICIOUS_CLONE_ALGORITHM,
SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTOR,
SCI_SYNCHRONIZED_COLLECTION_ITERATORS,
Oops, something went wrong.

0 comments on commit 3bcefd7

Please sign in to comment.