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] Make ConfusingTernary != null configurable · Issue #6004 · pmd/pmd

[java] Make ConfusingTernary != null configurable #6004

New issue
Copy link
New issue
Copy link
Closed
#6116
Closed
[java] Make ConfusingTernary != null configurable#6004
#6116
Copy link
Labels
an:enhancementAn improvement on existing features / rules
Milestone
7.18.0

Description

@delanym
delanym
opened on Aug 20, 2025
Issue body actions

For the rule https://docs.pmd-code.org/latest/pmd_rules_java_codestyle.html#confusingternary

this issue #278 made a comparison with != null a positive condition.

I think this should rather be made configurable:

<rule ref="category/java/codestyle.xml/ConfusingTernary">
    <properties>
        <property name="ignoreElseIf" value="false" />
        <property name="ignoreNulls" value="true" />
    </properties>
</rule>

The reason is that I don't want null guards being performed by my if statements. I don't need this change to do that (I can just search for all cases of != null AND == null) but until I have refactored, I want this rule to work for both cases.

In Modern Java we have the Objects.requireNonNull and more recently the JSpecify annotations to deal with these cases.
Not to mention the forecoming efforts in the Valhalla project to eliminate nulls. https://www.youtube.com/watch?v=6C1RaVwpCNc

I want to push null checks into the background and not have them part of my control flow statements, clogging up my coverage metrics, etc.

PMD 3.27.0

Activity

  1. delanym
    added
    a:false-negativePMD doesn't flag a problematic piece of code
    on Aug 20, 2025
  2. zbynek commented on Sep 30, 2025

    @zbynek
    zbynek
    on Sep 30, 2025 · Hidden as outdated
    show commentMore actions
  3. delanym commented on Sep 30, 2025

    @delanym
    delanym
    on Sep 30, 2025
    Author
    More actions

    @zbynek that's not the case - perhaps I confused the issue by discussing "why" i want what I want. So let me re-iterate:

    I would like the "confusing ternary" rule to be configurable so that if (x == null) { c(); } else {b(); } can be allowed while if (x != null) { b(); } else {c(); } considered a violation.

    And furthermore, I don't think this should be the only way this rule operates: I think this should be configurable. The rule should be able to work as it currently does OR how it did before #278.

  4. zbynek commented on Sep 30, 2025

    @zbynek
    zbynek
    on Sep 30, 2025
    Contributor
    More actions

    @delanym thanks, makes sense. So basically the property would be nullCheckBranch=then|else|any where nullCheckBranch=any is the current default, nullCheckBranch=then is the old behavior and nullCheckBranch=else is forcing

    if (x != null) { } else { }
    
    Reacted by Delany
  5. oowekyala
    closed this as completedin #6116on Oct 19, 2025
  6. adangel
    added this to the 7.18.0 milestone on Oct 21, 2025
  7. adangel
    changed the title [-]Make ConfusingTernary != null configurable[/-] [+][java] Make ConfusingTernary != null configurable[/+] on Oct 21, 2025
  8. adangel
    added
    an:enhancementAn improvement on existing features / rules
    and removed
    a:false-negativePMD doesn't flag a problematic piece of code
    on Oct 21, 2025
  9. adangel
    added a commit that references this issue on Oct 21, 2025

    [doc] Update release notes (#6004)

    4245337
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

    an:enhancementAn improvement on existing features / rules

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.18.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.