From 4574cb251c01495a06cfafcef585c4909a8e8623 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sun, 5 Nov 2023 21:42:29 +0100 Subject: [PATCH] [apex] Fix AvoidNonExistentAnnotationsRule for enum values --- .../errorprone/AvoidNonExistentAnnotationsRule.java | 3 +++ .../errorprone/xml/AvoidNonExistentAnnotations.xml | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/errorprone/AvoidNonExistentAnnotationsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/errorprone/AvoidNonExistentAnnotationsRule.java index d90c5d0a38..4d34bec452 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/errorprone/AvoidNonExistentAnnotationsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/errorprone/AvoidNonExistentAnnotationsRule.java @@ -59,6 +59,9 @@ public class AvoidNonExistentAnnotationsRule extends AbstractApexRule { } private Object checkForNonExistentAnnotation(final ApexNode node, final ASTModifierNode modifierNode, final Object data) { + if (modifierNode == null) { + return data; + } for (ASTAnnotation annotation : modifierNode.findChildrenOfType(ASTAnnotation.class)) { if (!annotation.isResolved()) { addViolationWithMessage(data, node, "Use of non existent annotations will lead to broken Apex code which will not compile in the future."); diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/AvoidNonExistentAnnotations.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/AvoidNonExistentAnnotations.xml index e5793809e9..1b57d75dc6 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/AvoidNonExistentAnnotations.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/AvoidNonExistentAnnotations.xml @@ -80,4 +80,14 @@ public class Foo { } ]]> + + + NPE for enum values (#4722) + 0 + +