FP java:S3516 with Lombok @Slf4j

  • What language is this for? Java
  • Which rule? S3516
  • Why do you believe it’s a false-positive/false-negative? The rule detects a method to return the same value, while the method returns clearly different values for different code paths.
  • Are you using
    • SonarLint - which IDE/version? SonarLint 10.0.1.77000 for IntelliJ
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
@Slf4j
class Foo {

  private static void confuse() {
    log.info("a message");
  }

  String bar() {
    if (new Random().nextInt() > 1) {
      return null; // FP 
    } 

    confuse(); // this is necessary to raise the FP

    return "something"; // FP
  } 

} 

2 Likes