I’m trying to use sonarcloud and sonarlint to catch more NPE exceptions. To test this i created a simple service and added some clearly problematic code but both sonarcloud and sonarlint don’t see the problem with rule java:S2259 and i can’t understand why!
After some more testing i discovered that if the annotation Log4j2(lombok) is used to autogenerate the “log” object and a method uses it then that method will never trigger S2259 if i remove from the method the “log” line or i manually create the “log” object then the rules are triggered. I don’t know what is going on and why is behaving like that.
The problem seems affect only the rule S2259, other rules works. Thanks for your help
@RestController
@RequestMapping(path = "rest/template-java", produces = MediaType.APPLICATION_JSON_VALUE)
@Log4j2
public class TemplateJavaController {
....
private int ruleNotTriggered() {
String a=null;
log.error("template");
return a.length();
}
private int ruleTriggered() {
String a=null;
return a.length();
}