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] SimplifyBooleanReturns triggers inconsistently depending on redundant parentheses in return expression · Issue #6694 · pmd/pmd

[java] SimplifyBooleanReturns triggers inconsistently depending on redundant parentheses in return expression #6694

New issue
Copy link
New issue
Copy link
Closed
#6922
Closed
[java] SimplifyBooleanReturns triggers inconsistently depending on redundant parentheses in return expression#6694
#6922
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
7.28.0

Description

@Chordrain
Chordrain
opened on May 18, 2026
Issue body actions

Affects PMD Version: 7.24.0

Rule: SimplifyBooleanReturns — https://docs.pmd-code.org/latest/pmd_rules_java_design.html#simplifybooleanreturns

Description:

SimplifyBooleanReturns is sensitive to purely syntactic parenthesization of the returned expression. Two semantically identical methods — one whose return expression is wrapped in a redundant outer pair of parentheses, the other not — are treated differently: the parenthesized form is flagged, the bare form is not. Since the rule targets the structural pattern if (c) return X; return false; (which should simplify to return c && X;), it should either flag both forms or neither. The discrepancy looks like the rule's AST matcher does not unwrap a ParenthesizedExpression node before checking the return-value shape, causing a false-negative on the unparenthesized form (or, equivalently, unstable behavior across trivially equivalent code).

Code Sample demonstrating the issue:

public class FactoryChecker {

    // BEFORE — NOT flagged by SimplifyBooleanReturns
    public boolean isFactoryMethodA(String qualifier, String name) {
        if (qualifier != null) {
            return typeEndsWith(qualifier, "Factory")
                || nameEndsWith(name);
        }
        return false;
    }

    // AFTER — flagged by SimplifyBooleanReturns (line of the `if`)
    public boolean isFactoryMethodB(String qualifier, String name) {
        if (qualifier != null) {
            return (typeEndsWith(qualifier, "Factory")
                || nameEndsWith(name));
        }
        return false;
    }

    private boolean typeEndsWith(String q, String suffix) { return q != null && q.endsWith(suffix); }
    private boolean nameEndsWith(String n) { return n != null && n.endsWith("Factory"); }
}

Expected outcome: Both methods (which are semantically identical) should receive the same verdict — either both are reported as simplifiable to return qualifier != null && (typeEndsWith(...) || nameEndsWith(...));, or neither is.

Actual outcome: Only isFactoryMethodB (with the redundant outer parentheses) is reported; isFactoryMethodA is silently accepted.

Running PMD through: CLI

Activity

  1. Chordrain
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on May 18, 2026
  2. Will-6543
    added a commit that references this issue on Aug 1, 2026

    Added testcase provied in issue pmd#6694

    6d280d0
  3. UncleOwen
    added this to the 7.28.0 milestone on Sep 8, 2026
  4. UncleOwen
    added a commit that references this issue on Sep 8, 2026

    [java] Fix #6694: Trigger SimplifyBooleanReturns when expressions req…

    This issue will close once commit bfa563c is merged into the 'main' branch.
    bfa563c
  5. UncleOwen
    closed this as completedin #6922on Sep 8, 2026
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

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