forked from phoedos/pmd
[apex] Exception applying rule UnusedLocalVariable on trigger
Fixes #2554
This commit is contained in:
@ -16,6 +16,9 @@ This is a {{ site.pmd.release_type }} release.
|
||||
|
||||
### Fixed Issues
|
||||
|
||||
* apex-bestpractices
|
||||
* [#2554](https://github.com/pmd/pmd/issues/2554): \[apex] Exception applying rule UnusedLocalVariable on trigger
|
||||
|
||||
### API Changes
|
||||
|
||||
### External Contributions
|
||||
|
@ -24,6 +24,10 @@ public class UnusedLocalVariableRule extends AbstractApexRule {
|
||||
String variableName = node.getImage();
|
||||
|
||||
ASTBlockStatement variableContext = node.getFirstParentOfType(ASTBlockStatement.class);
|
||||
if (variableContext == null) {
|
||||
// if there is no parent BlockStatement, e.g. in triggers
|
||||
return data;
|
||||
}
|
||||
|
||||
List<ApexNode<?>> potentialUsages = new ArrayList<>();
|
||||
|
||||
|
@ -83,6 +83,17 @@ public class Foo {
|
||||
public String fieldUsage() {
|
||||
return myfield;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>NPE with triggers (#2554)</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
trigger leadOwnerUpdate on Lead (after update) {
|
||||
for(Lead Id : Trigger.new) {
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
Reference in New Issue
Block a user