GeezerVison is showing github.com — [java] CompareObjectsWithEqualsRule trigger by enum1 != enum2 · Issue #885 · pmd/pmd
[java] CompareObjectsWithEqualsRule trigger by enum1 != enum2 #885
Description
Affects PMD Version:
6.0.1
Rule:
CompareObjectsWithEquals
Description:
enum1 != enum2 triggers CompareObjectsWithEquals.
I've seen there is code in CompareObjectsWithEqualsRule.java that says "skip, if it is an enum", but it doesn't.
Code Sample demonstrating the issue:
public static void assertEquals(final Enum<?> enum1,
final Enum<?> enum2,
final UUID errorKey,
final Object... errorArgs)
throws ResponseException
{
if (enum1 != enum2)
{
throw new ResponseException(errorKey, errorArgs);
}
}
Running PMD through: [CLI | Gradle]
Activity
d1ss0nanz commented on Jan 26, 2018
As a workaround, this can be suppressed via:
<rule ref="category/java/errorprone.xml/CompareObjectsWithEquals">
<properties>
<property name="violationSuppressXPath"
value="PrimaryExpression[typeof('java.lang.Enum')]" />
</properties>
lukechi1219 commented on May 7, 2018
Hi there,
I'm using eclipse-plugin with latest PMD 6.3.0
I found this not working for me
< property name="violationSuppressXPath" value="PrimaryExpression[typeof('java.lang.Enum')]" / >
but this works for me
< property name="violationSuppressXPath" value="[typeof('java.lang.Enum')]" / >
as in https://pmd.github.io/pmd-6.3.0/pmd_userdocs_suppressing_warnings.html
this doesn't work for me, either.
< property name="violationSuppressXPath" value=".[typeof('java.lang.Enum')]" / >
are those 2 type errors?
value="PrimaryExpression[typeof('java.lang.Enum')]"
value=".[typeof('java.lang.Enum')]"
jsotuyod commented on May 7, 2018
The correct grammar would be .[typeof(@Image, 'java.lang.Enum', 'Enum')].... I doubt the single argument typeof is working.... I'd have to verify it and update the docs.
Metadata
Metadata
Development
No branches or pull requestsIssue actions