[apex] UnusedLocalVariable - false positive on case insensitivity allowed in Apex
Fixes #2626
This commit is contained in:
@ -16,6 +16,9 @@ This is a {{ site.pmd.release_type }} release.
|
||||
|
||||
### Fixed Issues
|
||||
|
||||
* apex-bestpractices
|
||||
* [#2626](https://github.com/pmd/pmd/issues/2626): \[apex] UnusedLocalVariable - false positive on case insensitivity allowed in Apex
|
||||
|
||||
### API Changes
|
||||
|
||||
### External Contributions
|
||||
|
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
@ -41,7 +41,7 @@ public class UnusedLocalVariableRule extends AbstractApexRule {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (usage.hasImageEqualTo(variableName)) {
|
||||
if (equalsIgnoreCase(variableName, usage.getImage())) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -49,4 +49,14 @@ public class UnusedLocalVariableRule extends AbstractApexRule {
|
||||
addViolation(data, node, variableName);
|
||||
return data;
|
||||
}
|
||||
|
||||
private static boolean equalsIgnoreCase(String a, String b) {
|
||||
if (a == b) {
|
||||
return true;
|
||||
}
|
||||
if (a == null || b == null) {
|
||||
return false;
|
||||
}
|
||||
return a.equalsIgnoreCase(b);
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,20 @@ public class Foo {
|
||||
trigger leadOwnerUpdate on Lead (after update) {
|
||||
for(Lead Id : Trigger.new) {
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>[apex] UnusedLocalVariable - false positive on case insensitivity allowed in Apex #2626</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
class Foo {
|
||||
private String foo() {
|
||||
String Bar;
|
||||
bar = 'bar';
|
||||
return bar;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
Reference in New Issue
Block a user