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] UnusedLocalVariable: false-negative with compound assignments · Issue #4517 · pmd/pmd

[java] UnusedLocalVariable: false-negative with compound assignments #4517

New issue
Copy link
New issue
Copy link
Closed
#4501
Closed
[java] UnusedLocalVariable: false-negative with compound assignments#4517
#4501
Copy link
Labels
a:false-negativePMD doesn't flag a problematic piece of code
Milestone
7.0.0

Description

@adangel
adangel
opened on Apr 28, 2023
Issue body actions

Affects PMD Version: 6.x

Rule: UnusedLocalVariable

Description:

If a variable is only used in a compound statement (e.g. +=), then this should not count as usage and a violation should be reported.

Note: This has already been fixed with PMD 7.0.0-rc1. (via #3113)
Found via #3123.

Code Sample demonstrating the issue:

public class UnusedCompoundAssignment {
    void this_is_unused() {
        int x = 0; // violation expected (line 3)
        x += 2;    // doesn't count as usage
    }
    void transitive_used_but_unused1() {
        int a = 1; // _no_ violation expected, a is used
        int b = a; // _no_ violation expected, b is used
        int c = b; // violation expected (line 9)
    }
    void transitive_used_but_unused2() {
        int a, b, c; // 1 violation expected, only c is unused (line 12)
        a = 1;
        b = a;
        c = b;
    }
    void transitive_used() {
        int a, b, c; // _no_ violation expected
        a = 1;
        b = a;
        c = b;
        System.out.println(c); // usage
    }
    void this_is_used() {
        int y = 0; // _no_ violation expected
        y += 2;
        System.out.println(y); // usage
    }
}

Expected outcome:

PMD should report a violation at line 3, but doesn't. This is a false-negative.

Activity

  1. adangel
    added
    a:false-negativePMD doesn't flag a problematic piece of code
    on Apr 28, 2023
  2. adangel
    added this to the 7.0.0 milestone on Apr 28, 2023
  3. adangel
    changed the title [-][java] UnusedLocalVariable false-positive with compound assignments[/-] [+][java] UnusedLocalVariable false-negative with compound assignments[/+] on Apr 28, 2023
  4. adangel
    changed the title [-][java] UnusedLocalVariable false-negative with compound assignments[/-] [+][java] UnusedLocalVariable: false-negative with compound assignments[/+] on Apr 28, 2023
  5. adangel
    closed this as completedin #4501on Apr 29, 2023
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.0.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.