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] UselessParentheses FP around switch expression · Issue #6123 · pmd/pmd

[java] UselessParentheses FP around switch expression #6123

New issue
Copy link
New issue
Copy link
Closed
#6130
Closed
[java] UselessParentheses FP around switch expression#6123
#6130
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
7.18.0

Description

@vbrandl
vbrandl
opened on Oct 8, 2025
Issue body actions

Affects PMD Version: 6.55.0, 7.13.0

Rule: UselessParentheses

Description:

When chaining a method call directly after a switch expression, the expression has to be wrapped into parentheses. Removing the parentheses is a syntax error (at least in Java 17.0.16). PMD detects this as a UselessParentheses rule violation.

Code Sample demonstrating the issue:

public class Main {
  public enum E {
    A, B;
  }

  public static String foo(final E e) {
    return (switch (e) {
      case A -> "bar";
      case B -> "baz";
    }).toUpperCase();
  }
}

Expected outcome:

PMD shouldn't detect the parentheses around the switch expression as UselessParentheses violation.

Running PMD through: CLI and Gradle

Activity

  1. vbrandl
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on Oct 8, 2025
  2. adangel
    changed the title [-][java] `UselessParentheses` around `switch` expression[/-] [+][java] UselessParentheses FP around switch expression[/+] on Oct 9, 2025
  3. oowekyala
    added this to the 7.18.0 milestone on Oct 19, 2025
  4. oowekyala
    closed this as completedin #6130on 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-positivePMD flags a piece of code that is not problematic

    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.