File tree Expand file tree Collapse file tree
main/java/org/sonar/java/checks Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525import org .sonar .check .Rule ;
2626import org .sonar .java .tag .Tag ;
2727import org .sonar .plugins .java .api .semantic .Symbol ;
28+ import org .sonar .plugins .java .api .semantic .Symbol .TypeSymbol ;
2829import org .sonar .plugins .java .api .tree .AnnotationTree ;
2930import org .sonar .plugins .java .api .tree .AssignmentExpressionTree ;
3031import org .sonar .plugins .java .api .tree .ExpressionTree ;
3435import org .sonar .squidbridge .annotations .SqaleSubCharacteristic ;
3536
3637import java .util .ArrayList ;
37- import java .util .Collection ;
3838import java .util .List ;
3939
4040@ Rule (
@@ -53,9 +53,12 @@ public List<Tree.Kind> nodesToVisit() {
5353 @ Override
5454 public void visitNode (Tree tree ) {
5555 AnnotationTree annotationTree = (AnnotationTree ) tree ;
56- Collection <Symbol > symbols = annotationTree .symbolType ().symbol ().memberSymbols ();
56+ TypeSymbol annotationSymbol = annotationTree .symbolType ().symbol ();
57+ if (annotationSymbol .isUnknown ()) {
58+ return ;
59+ }
5760 List <String > declarationNames = new ArrayList <>();
58- for (Symbol symbol : symbols ) {
61+ for (Symbol symbol : annotationSymbol . memberSymbols () ) {
5962 declarationNames .add (symbol .name ());
6063 }
6164 List <String > annotationArguments = new ArrayList <>();
Original file line number Diff line number Diff line change 11import org .sonar .java .checks .targets .CustomAnnotation ;
2+ import org .sonar .java .MyUnknownAnnotation ;
23
34@interface MyAnnotation {
45 String myName ();
@@ -22,4 +23,7 @@ void wrongMethod() {
2223
2324 List <@ MyAnnotation (myInteger =2 , myName ="XXX" ) Object []> field ;// Noncompliant
2425 List <@ MyAnnotation (myName ="XXX" , aaaLast = "" ) Object []> field ;
25- }
26+ }
27+
28+ @ MyUnknownAnnotation (name = "XXX" ) // Compliant
29+ class MySecondClass {}
You can’t perform that action at this time.
0 commit comments