GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] CompareObjectsWithEqualsRule trigger by enum1 != enum2 · Issue #885 · pmd/pmd

[java] CompareObjectsWithEqualsRule trigger by enum1 != enum2 #885

New issue
Copy link
New issue
Copy link
Closed
Closed
[java] CompareObjectsWithEqualsRule trigger by enum1 != enum2#885
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.1.0

Description

@d1ss0nanz
d1ss0nanz
opened on Jan 26, 2018
Issue body actions

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

  1. d1ss0nanz commented on Jan 26, 2018

    @d1ss0nanz
    d1ss0nanz
    on Jan 26, 2018
    Author
    More actions

    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>
    
  2. jsotuyod
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on Jan 26, 2018
  3. jsotuyod
    added this to the 6.1.0 milestone on Jan 26, 2018
  4. jsotuyod
    added
    has:pr
    on Jan 27, 2018
  5. jsotuyod
    closed this as completedin #886on Jan 27, 2018
  6. lukechi1219 commented on May 7, 2018

    @lukechi1219
    lukechi1219
    on May 7, 2018
    More actions

    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')]"

  7. jsotuyod commented on May 7, 2018

    @jsotuyod
    jsotuyod
    on May 7, 2018
    Member
    More actions

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

      Milestone

      • 6.1.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.