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] CollapsibleIfStatements: not reported when a bare block separates the two if statements · Issue #7328 · pmd/pmd

[java] CollapsibleIfStatements: not reported when a bare block separates the two if statements #7328

New issue
Copy link
New issue
Copy link
Done
#7336
#7339
Done
[java] CollapsibleIfStatements: not reported when a bare block separates the two if statements#7328
#7336
#7339
Copy link
Milestone
7.31.0

Description

@MarkLee131
MarkLee131
opened on Nov 11, 2026
Issue body actions

Affects PMD Version: 7.28.0

Rule: CollapsibleIfStatements, https://docs.pmd-code.org/latest/pmd_rules_java_design.html#collapsibleifstatements

Description:

The nested if in CifSeed.bar is reported (can be merged into if (x > 1 && y > 1)). With a bare block between the two (CifVariant.bar) it isn't. The XPath only accepts IfStatement/IfStatement and IfStatement/Block[count(*) = 1]/IfStatement.

Code Sample demonstrating the issue:

CifSeed.java:

public class CifSeed {
    void bar(int x, int y) {
        if (x > 1) {
            if (y > 1) {                            // CollapsibleIfStatements
                System.out.println(x + y);
            }
        }
    }
}

CifVariant.java:

public class CifVariant {
    void bar(int x, int y) {
        if (x > 1) {
            {
                if (y > 1) {                        // the same nesting: not reported
                    System.out.println(x + y);
                }
            }
        }
    }
}

Run:

pmd check -d CifSeed.java,CifVariant.java \
    -R category/java/design.xml/CollapsibleIfStatements -f text

Expected outcome:

CollapsibleIfStatements on the inner if of CifVariant.bar (line 5), as on CifSeed.bar (line 4).

Running PMD through: CLI

See also #7275.

Output of the commands above:

### PMD
PMD 7.28.0 (79726f0e8f46c1a9954a3f9880f6d15c91bf6387, 2026-09-25T07:52:15Z)
Java version: 25.0.3, vendor: Eclipse Adoptium, runtime: <path>  rule: CollapsibleIfStatements

--- SEED (CifSeed.java) -- expected: reported
CifSeed.java:4:	CollapsibleIfStatements:	This if statement could be combined with its parent
[INFO] Found 1 violation.

--- VARIANT (CifVariant.java) -- expected: reported; actual: not reported
[INFO] Found no violations.

(PMD exits 4 when it reports violations; empty output above = no violation)

Activity

  1. UncleOwen
    added this to the 7.31.0 milestone on Nov 27, 2026
  2. UncleOwen
    closed this as completedin 1f9fa8aon Nov 27, 2026
  3. UncleOwen
    added a commit that references this issue on Nov 27, 2026

    [java] Fix pmd#7328: CollapsibleIfStatements: report nested if behind…

    This issue will close once commit 1f9fa8a is merged into the 'main' branch.
    1f9fa8a
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

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