Log statement with no args passed for the placeholder are not detected by any rules

Java
SonarQube: v10.5 (89998)
SonarLint: 10.5.0.78339

There are no issues detected with the following code. This is a false negative.

@Slf4j
public class TestClass {
  public void func() {
    log.warn("This log has no arguments, but it should: {}");
  }
}

Luckily IntelliJ catches this issue and I was able to find 15 other occurrences in my project where someone had passed the wrong number of args for the number of placeholders they specified.

Hello @lbenedetto,

Thank you for reporting this false negative. Can you confirm that you’re referring to the rule S3457 and the @Slf4j annotation is from Lombok?

Cheers,

Angelo

Yes, that rule seems relevant. It’s possible there’s a more specific rule, but I don’t know.

Yes the Slf4j annotation is Lombok, but is probably not relevant. I expect you’d see the issue no matter how you inject the logger instance.

The use of Lombok annotations is relevant because it uses its own AST by modifying the existing AST. The Java Analyzer uses the Eclipse AST, so all the Lombok annotations are not processed and thus missing from the AST. For this reason, the Analyzer doesn’t have any information about fields autogenerated by Lombok annotations.

I created anyway the issue [SONARJAVA-5014] - Jira to investigate if it’s somehow possible to cover this false negative. In general, we can’t deal with Lombok annotations, so the strategy is to allow false negatives.

Cheers,
Angelo

1 Like