Affects PMD Version:
6.36.0
Rule:
UnusedNullCheckInEquals
Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_errorprone.html#unusednullcheckinequals
Description:
There are five cases that generate false positives:
-
Using Arrays.equals()
-
Using Bytes.equals()
- The first and second cases don't use null checks.
-
Using overridden equals() that has more than two arguments
- This case also doesn't need null checks for comparanda.
-
.class.getName() doesn't return null
-
null checked in condition of conditional expression
- After null checked in
condition part of conditional expression,
PMD generates alarms.
Code Sample demonstrating the issue:
class UnusedNullCheckInEquals{
void test(){
//case1: Arrays.equals()
if (other.name != null && java.util.Arrays.equals(other.name,name));
//case2: Bytes.equals()
if (startRow != null && startRow.length > 0 && Bytes.equals(startRow,stopRow));
//case3: oveerriden equals() that has more than two arguments
if (k1 == k2 || (k1 != null && hashingStrategy.equals(k1, k2)));
if (passthroughNsPrefix != null &&
LexerUtils.equals(passthroughNsPrefix, attribute.namespacePrefix(), true, true));
//case4: .class.getName() cannot return null
if (driverDelegate != null &&
StdJDBCDelegate.class.getName().equals(driverDelegate));
//case5: null checked in condition of conditional expression
if (this.start == other.start && this.length == other.length &&
(this.file == null ?
other.file == null : (other.file != null && this.file.equals(other.file))));
}
}
Expected outcome:
PMD shouldn't report anything. These are false positives.
Thank you for your consideration.
Running PMD through: [CLI]
Affects PMD Version:
6.36.0
Rule:
UnusedNullCheckInEquals
Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_errorprone.html#unusednullcheckinequals
Description:
There are five cases that generate false positives:
Using
Arrays.equals()Using
Bytes.equals()Using
overridden equals() that has more than two arguments.class.getName()doesn't return nulljavadocofclass.getName(), it doesn't returnnull.So, it is okay to use as the
callerofequals().Ref. https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getName--
null checked in
conditionofconditional expressionconditionpart ofconditional expression,PMD generates alarms.
Code Sample demonstrating the issue:
Expected outcome:
PMD shouldn't report anything. These are false positives.
Thank you for your consideration.
Running PMD through: [CLI]