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 — [apex] Unused Local Variable fails on blocks · Issue #2468 · pmd/pmd

[apex] Unused Local Variable fails on blocks #2468

New issue
Copy link
New issue
Copy link
Closed
#2469
Closed
[apex] Unused Local Variable fails on blocks#2468
#2469
Copy link
Assignees
gwilymatgearset
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.24.0

Description

@rsoesemann
rsoesemann
opened on May 6, 2020
Issue body actions

Affects PMD Version:
6.23

Rule: UnusedLocalVariable

Description:

The rule added in PR #2395 by @gwilymatgearset is way too simplistic and only checks the code in the current block for used or unused. As soon as the variable is used in a nested block (if/for) it's detected as unused.

public void foo() {
    Integer used;

    if(true) {
        for(Integer i=0; i<10; i++) {
            used++;
        }
    }
}

Activity

  1. rsoesemann
    added
    a:bugPMD crashes or fails to analyse a file.
    on May 6, 2020
  2. rsoesemann
    assigned
    gwilymatgearset
    on May 6, 2020
  3. rsoesemann
    changed the title [-][apex] Unused Local Variable is reporting only False Positives[/-] [+][apex] Unused Local Variable fails on blocks[/+] on May 6, 2020
  4. rsoesemann
    added
    a:false-positivePMD flags a piece of code that is not problematic
    and removed
    a:bugPMD crashes or fails to analyse a file.
    on May 6, 2020
  5. gwilymatgearset commented on May 6, 2020

    @gwilymatgearset
    gwilymatgearset
    on May 6, 2020
    Collaborator
    More actions

    @rsoesemann I've added your test case to the tests, but it still passes :/. Code-wise, I don't see why it wouldn't work so I'm a little confused.

    gwilymatgearset@6b23a8e

  6. gwilymatgearset commented on May 6, 2020

    @gwilymatgearset
    gwilymatgearset
    on May 6, 2020
    Collaborator
    More actions

    I think I've figured it out:

        public void usedInBlocks() {
            String foo = 'foobar';
            return foo.substringAfter('foo');
        }

    triggers an unused warning for foo. I'll try and get that fixed today :)

    Reacted by Robert Sösemann
  7. pmd
    deleted a comment from gwilymatgearset on May 6, 2020
  8. rsoesemann
    closed this as completedin #2469on May 7, 2020
  9. adangel
    added this to the 6.24.0 milestone on May 8, 2020
  10. adangel
    added a commit that references this issue on May 8, 2020

    [doc] Update release notes, refs #2469, fixes #2468

    This issue will close once commit b740225 is merged into the 'main' branch.
    b740225
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @gwilymatgearset
    gwilymatgearset

Labels

a:false-positivePMD flags a piece of code that is not problematic

Type

No type

Projects

No projects

    Milestone

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