!unknownSymbol! getting annotations names

63 views
Skip to first unread message

Bruna Guize Sponchiado

unread,
Jun 7, 2018, 4:37:43 PM6/7/18
to SonarQube
Hey guys. I'm just getting into developing new rules for SonarJava and my first rule will be about class annotations when they meet some naming pattern.
I was trying to create some rules and it was not working at all. Then I created some code to report an issue for every annotation found and then I realized that i was getting "!unknownSymbol!" for 80% of my project annotations. Some of them are working just fine.
Here's my code:


public class EntityAnnotationRule extends IssuableSubscriptionVisitor {

@Override
public List<Kind> nodesToVisit() {
return ImmutableList.of(Kind.CLASS);
}

@Override
public void visitNode(Tree tree) {
ClassTree clazzTree = (ClassTree) tree;

if (checkClazzNamePattern(clazzTree.symbol().name())) {
for (AnnotationTree annotationTree : clazzTree.modifiers().annotations()) {
reportIssue(annotationTree, "Has Annotation: " + annotationTree.symbolType().name());
}
}

}

private boolean checkClazzNamePattern(String name) {
return name.contains("SomePattern");
}
}

Any thoughts on this?

Thank you.

Nicolas Peru

unread,
Jun 8, 2018, 2:36:20 AM6/8/18
to Bruna Guize Sponchiado, SonarQube
Hi, 

What is the SonarJava version used ? How do you run your analysis (which scanner) and most importantly : is the .class file of your annotation provided to the analyzer (via sonar.java.binaries or sonar.java.libraries)? 

Cheers, 

--
Important: this SonarQube Google Group will close on June 11th, 2018, in order to move to a new forum to power even more community discussions. See details in this post: https://groups.google.com/d/msg/sonarqube/BbSZz-JnhVM/DavhMueEAAAJ
---
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/a677724b-39d2-4f19-8001-45237ed6a4dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas Peru | SonarSource

Bruna Guize Sponchiado

unread,
Jun 8, 2018, 8:33:43 AM6/8/18
to SonarQube
Hi Nicolas!

I'm using the following setup:
SonarQube 6.7.4
SonarJava 5.4
SonarScanner 3.2.0

Also sonar.java.binaries=target/classes is on my sonar-project.properties file

Weird thing is: some annotations like @Entity are being recognized in some classes and not in others that are in the same modules and packages.

Cheers!

Bruna Guize Sponchiado

unread,
Jun 8, 2018, 10:36:39 AM6/8/18
to SonarQube
OK Guys. Got it working with Maven analysis :)

Thank you for your time.
Reply all
Reply to author
Forward
0 new messages