The following code results in a "Using .equals to compare two int[]'s, (equivalent to ==)" warning in FindBugs 2.0.0. FindBugs 1.3.9 didn't create a warning.
int[] numbers = { 1, 2, 3 };
int[] numbers2 = { 1, 2, 3 };
org.testng.Assert.assertEquals(numbers, numbers2);
As Dave Brosius found out, there seems to be a class name check missing in FindRefComparison:
InvokeInstruction inv = (InvokeInstruction) ins;
@DottedClassName String className = inv.getClassName(cpg);
String methodName = inv.getMethodName(cpg);
String methodSig = inv.getSignature(cpg);
if ( methodName.equals("assertSame") && methodSig.equals("(Ljava/lang/Object;Ljava/lang/Object;)V")) {
checkRefComparison(location, jclass, method, methodGen, visitor, typeDataflow, stringComparisonList,
refComparisonList);
}
boolean equalsMethod = methodName.equals("equals") && methodSig.equals("(Ljava/lang/Object;)Z")
|| methodName.equals("assertEquals") && methodSig.equals("(Ljava/lang/Object;Ljava/lang/Object;)V")
|| methodName.equals("equal") && methodSig.equals("(Ljava/lang/Object;Ljava/lang/Object;)Z")
&& className.equals("com.google.common.base.Objects");
if (equalsMethod) {
checkEqualsComparison(location, jclass, method, methodGen, cpg, typeDataflow);
}
That code should probably check for org.junit.Assert or junit.Assert
Note: TestNG's Assert can handle arrays in the assertEquals method fine:
static public void assertEquals(Object actual, Object expected, String message) {
if((expected == null) && (actual == null)) {
return;
}
if(expected != null) {
if (expected.getClass().isArray()) {
assertArrayEquals(actual, expected, message);
return;
} else if (expected.equals(actual)) {
return;
}
}
failNotEquals(actual, expected, message);
}
I'm not sure if the real problem is that there should be a check for junit.Assert; an argument could be made that TestNG is busted, since the objects aren't equal.
Added a check for org.testng.Assert