A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/2626 below:

[apex] UnusedLocalVariable - false positive on case insensitivity allowed in Apex · Issue #2626 · pmd/pmd · GitHub

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4