ClassCastException in PublicApiChecker

Version:

  • java-frontend-5.14.0.18788.jar

When implementing a custom Java rule in my organisation and using PublicApiChecker i get the following error:

java.lang.ClassCastException: org.sonar.java.model.statement.StaticInitializerTreeImpl cannot be cast to org.sonar.plugins.java.api.tree.ClassTree
at org.sonar.java.ast.visitors.PublicApiChecker.isPublicApi(PublicApiChecker.java:146)

Hello,

PublicApiChecker is not part of the java Analyzer public API to write custom rules. Therefore you can’t use it in your custom rules. I would recommend you to duplicate the logic in your rule.

Cheers,
Michael

Thansk for the info, i solved the problem in another fashion (somewhat mimicking the internals of PublicApiChecker but reduced to the specific need)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.