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)
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.