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] AvoidDeeplyNestedIfStmts violations can be unintentionally undetected · Issue #1499 · pmd/pmd

[java] AvoidDeeplyNestedIfStmts violations can be unintentionally undetected #1499

New issue
Copy link
New issue
Copy link
Closed
#6100
Closed
[java] AvoidDeeplyNestedIfStmts violations can be unintentionally undetected#1499
#6100
Copy link
Labels
a:false-negativePMD doesn't flag a problematic piece of code
Milestone
7.18.0

Description

@HoushCE29
HoushCE29
opened on Dec 3, 2018
Issue body actions

Affects PMD Version: 5.3.3, 6.*, 7.0.0

Rule: design/AvoidDeeplyNestedIfStatements

Description: This rule has strange behavior where if you dispatch from an else block from somewhere else to a method containing violating deeply nested if code, it doesn't get caught as a violation. But if you do a simple if block but no else block, then it gets caught as a violation.

It's hard to explain without writing a book.... so see the sample code...

Code Sample demonstrating the issue:

This is a sample violating method:

private String doSomething(String somethingToDo) {
    if (condition) {
        if (anotherCondition) {
            if (problemDepthCondition) {
                return SOMETHING;
            }
        }
    }
    return SOMETHING_ELSE;
}

Here is code that the violation is caught for:

public String performSomething(String action) {
    if (action.equals(NOTHING)) {
        return NOTHING;
    }
    return doSomething(action);
}

However, this code (which is effectively the same) allows the violation:

public String performSomething(String action) {
    if (action.equals(NOTHING)) {
        return NOTHING;
    }
    // Only difference: using an else block
    else {
        return doSomething(action);
    }
}

Sure, the nested if's can and should be avoided and rewritten, but I would expect that if someone did code that way (which is what happened and why I am bringing up this issue) that it would be caught, even in the else block...

Please let me know if this actually isn't an issue (and is expected behavior), or if further clarification is needed.

Running PMD through: Gradle

Activity

  1. jsotuyod commented on Dec 3, 2018

    @jsotuyod
    jsotuyod
    on Dec 3, 2018
    Member
    More actions

    @HoushCE29 thanks for the report!

    You seem to be using a really old PMD version (latest version is PMD 6.9.0, with 6.10.0 upcoming). Can you please double check the problem persists under 6.9.0?

  2. HoushCE29 commented on Dec 3, 2018

    @HoushCE29
    HoushCE29
    on Dec 3, 2018
    Author
    More actions

    @jsotuyod Will do! I'll get back to you in the next week.

  3. HoushCE29 commented on Dec 4, 2018

    @HoushCE29
    HoushCE29
    on Dec 4, 2018
    Author
    More actions

    @jsotuyod Confirmed, it does in fact do that same behavior with version 6.9.0.

    Do you require a copy of my "test-case" mini Gradle project for further evaluation?

  4. jsotuyod
    added
    a:false-negativePMD doesn't flag a problematic piece of code
    on Dec 10, 2018
  5. jsotuyod commented on Dec 10, 2018

    @jsotuyod
    jsotuyod
    on Dec 10, 2018
    Member
    More actions

    @HoushCE29 shouldn't be necessary, thanks!

    Reacted by Charlie Housh
  6. adangel commented on Dec 10, 2018

    @adangel
    adangel
    on Dec 10, 2018
    Member
    More actions

    It seems to be related to https://sourceforge.net/p/pmd/bugs/44/ - I was wondering, whether we always excluded somehow the else-branch. And we do this pretty long now (since 2002 - 7e4cdbd).
    I agree, that adding an else, should not silence the rule...

    Reacted by Charlie Housh
  7. jsotuyod
    added
    needs:pmd7-revalidationThe issue hasn't yet been retested vs PMD 7 and may be stale
    and removed
    needs:pmd7-revalidationThe issue hasn't yet been retested vs PMD 7 and may be stale
    on Mar 17, 2024
  8. oowekyala
    added this to the 7.18.0 milestone on Oct 19, 2025
  9. oowekyala
    closed this as completedin #6100on Oct 19, 2025
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-negativePMD doesn't flag a problematic piece of code

    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.