Affects PMD Version:6.42.0
Rule:CompareObjectsWithEquals
Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_errorprone.html#compareobjectswithequals
Description:
Hi, I found a FN about this rule. PMD should have reported a warning in line 5 because here a is compared by ==, not equals. However, line 8 can get a warning and they are equivalent. Hence, I think this is a false negative.
This issue is caused by the incorrect result of count(PrimaryExpression[pmd-java:typeIs('java.lang.Object')])=2 in defined XPath rule, typeIs fails to recognize b[get()] as java.lang.Object.
Code Sample demonstrating the issue:
int get() {
return 1;
}
void array1(String[] a, String[] b) {
if (a[1] == b[get()]) {} // should report a warning
}
void array2(String[] a, String[] b) {
if (a[1] == b[1]) {} // can detect
}
Expected outcome:
PMD should report a violation at line 5, but doesn't. This is a false-negative.
Running PMD through: [Maven]
Affects PMD Version:6.42.0
Rule:CompareObjectsWithEquals
Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_errorprone.html#compareobjectswithequals
Description:
Hi, I found a FN about this rule. PMD should have reported a warning in line 5 because here a is compared by
==, notequals. However, line 8 can get a warning and they are equivalent. Hence, I think this is a false negative.This issue is caused by the incorrect result of
count(PrimaryExpression[pmd-java:typeIs('java.lang.Object')])=2in defined XPath rule,typeIsfails to recognizeb[get()]asjava.lang.Object.Code Sample demonstrating the issue:
Expected outcome:
PMD should report a violation at line 5, but doesn't. This is a false-negative.
Running PMD through: [Maven]