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] LocalVariableCouldBeFinal: False negative when multiple variables are declared at once · Issue #6602 · pmd/pmd

[java] LocalVariableCouldBeFinal: False negative when multiple variables are declared at once #6602

New issue
Copy link
New issue
Copy link
Closed
#6603
Closed
[java] LocalVariableCouldBeFinal: False negative when multiple variables are declared at once#6602
#6603
Copy link
Labels
a:false-negativePMD doesn't flag a problematic piece of code
Milestone
7.25.0

Description

@UncleOwen
UncleOwen
opened on Apr 17, 2026
Issue body actions

Affects PMD Version: 7.23.0

Rule: LocalVariableCouldBeFinal

Description: When multiple variables are declared in the same line, and some of them could be final, LocalVariableCouldBeFinal is not raised.

Code Sample demonstrating the issue:

class Foo {
    void foo(boolean cond1) {
        int i=0, j=1;

        if (cond1) {
            i = 3;
        }

        IO.println(i + " " + j);
    }
}

Expected outcome:

PMD should report a violation at line 3, but doesn't. This is a false-negative. If I split up the two declarations, there is a violation for j.

PMD does report a OneDeclarationPerLine violation for the above code. I'm aware of PMDs policy to only report one violation for one issue. But PMD also actively encourages users to pick and choose which rules to enable. I find it very surprising that the above code doesn't raise a violation if LocalVariableCouldBeFinal is enabled (and OneDeclarationPerLine is not).

Running PMD through: CLI

Activity

  1. UncleOwen
    added
    a:false-negativePMD doesn't flag a problematic piece of code
    on Apr 17, 2026
  2. UncleOwen commented on Apr 17, 2026

    @UncleOwen
    UncleOwen
    on Apr 17, 2026
    MemberAuthor
    More actions

    Looking at #1619, I was wrong that this is about OneDeclarationPerLine. It's about multiple variables that are declared in a loop header. Maybe we should restrict the special handling to loop headers then?

  3. adangel
    changed the title [-][java] false negative in LocalVariableCouldBeFinal when multiple variables are declared in the same line[/-] [+][java] LocalVariableCouldBeFinal: False negative when multiple variables are declared in the same line[/+] on May 7, 2026
  4. adangel
    changed the title [-][java] LocalVariableCouldBeFinal: False negative when multiple variables are declared in the same line[/-] [+][java] LocalVariableCouldBeFinal: False negative when multiple variables are declared at once[/+] on May 7, 2026
  5. adangel
    added this to the 7.25.0 milestone on May 14, 2026
  6. adangel
    added a commit that references this issue on May 14, 2026

    [doc] Update release notes (#6602, #6603)

    0c642e3
  7. adangel
    closed this as completedin ed1c6b1on May 14, 2026
  8. adangel
    added a commit that references this issue on May 14, 2026

    [java] Fix pmd#6602: Fix false negative in LocalVariableCouldBeFinalR…

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