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] UnusedLocalVariable - false positive on case insensitivity allowed in Apex · Issue #2626 · pmd/pmd

[apex] UnusedLocalVariable - false positive on case insensitivity allowed in Apex #2626

New issue
Copy link
New issue
Copy link
Closed
#2630
Closed
[apex] UnusedLocalVariable - false positive on case insensitivity allowed in Apex#2626
#2630
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.26.0

Description

@mvenneman
mvenneman
opened on Jul 1, 2020
Issue body actions

Affects PMD Version:
6.24.0

Rule:
UnusedLocalVariable

Description:
Apex local variables are case-INsensitive. The UnusedLocalVariable rule flags a variable declaration if that variable NOT used with the same case, but IS used with a different case. Apex code will work as intended, and in Apex this is not an unused variable.

https://github.com/pmd/pmd/blob/master/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/UnusedLocalVariableRule.java

Code Sample demonstrating the issue:

private String foo() {
   String Bar;
   bar = "bar";
   return bar; 
}

Expected outcome:
PMD should not report an UnusedLocalVariable violation in the above code sample, because bar is an acceptable reference to the originally declared Bar in Apex syntax.

In the rule's code, this can be addressed with another if statement in the for loop iterating over potentialUsages, such as:

if (usage.getImage() != null && usage.getImage().compareToIgnoreCase(variableName) == 0) {
   return data;
}

This issue cannot be addressed in the ApexNode.hasImageEqualTo() method because that method is used across languages where case-sensitivity is enforced (i.e. Java).

Running PMD through:
CLI and "Apex PMD" VS Code extension

Reacted by Andreas Dangel

Activity

  1. mvenneman
    added
    a:bugPMD crashes or fails to analyse a file.
    on Jul 1, 2020
  2. mvenneman commented on Jul 1, 2020

    @mvenneman
    mvenneman
    on Jul 1, 2020
    Author
    More actions

    Label needs to be changed from bug to false-positive.

  3. adangel
    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 Jul 1, 2020
  4. adangel
    added a commit that references this issue on Jul 2, 2020

    [apex] UnusedLocalVariable - false positive on case insensitivity all…

    This issue will close once commit 147f1ac is merged into the 'main' branch.
    147f1ac
  5. oowekyala
    closed this as completedin 147f1acon Jul 3, 2020
  6. oowekyala commented on Jul 3, 2020

    @oowekyala
    oowekyala
    on Jul 3, 2020
    Member
    More actions

    I wonder, whether it would make sense to make a rule to enforce that identifiers are always used in the same case. I'm not an apex developer, so I can't really tell

  7. adangel
    added this to the 6.26.0 milestone on Jul 3, 2020
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

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