51 public void addHtmlDescription(NewRule rule) {
52 URL resource = ExternalDescriptionLoader.class.getResource(resourceBasePath + "/" + rule.key() + ".html");
53 if (resource != null) {
54 addHtmlDescription(rule, resource);55 }
56 }
57
88 new RulesDefinitionAnnotationLoader().load(repository, Iterables.toArray(ruleClasses, Class.class));
89 List<NewRule> newRules = Lists.newArrayList();
90 for (var ruleClass : ruleClasses) {
91 var rule = newRule(ruleClass, failIfNoExplicitKey); 92 externalDescriptionLoader.addHtmlDescription(rule);
93 rule.setTemplate(AnnotationUtils.getAnnotation(ruleClass, RuleTemplate.class) != null);
94 if (!isSqaleAnnotated(ruleClass) && failIfSqaleNotFound) {
A method/constructor that is marked with annotations such as @VisibleForTesting
or @TestOnly
should not be called from non-test code, as such declarations are only meant to be used as test helpers.
Remove/replace the usage with an alternative that does not use such methods if possible.
If this issue does not apply in your case, mark the line where it is reported with a // skipcq: JAVA-A1067
comment.
class SomeClass
@TestOnly
void onlyForTests() {
// ...
}
}
class SomeOtherClass {
void nonTestMethod(SomeClass someObject) {
someObject.onlyForTests(); // Bad!
}
}
Avoid using such methods unless there is absolutely no other way, and ensure that the usage of such methods cannot trigger any bugs.