False positive from java:S1105 in record class

“An open curly brace should be located at the end of a line”

I like to format code like this, but S1105 complains about the ) { for the record even though it is fine with the ) { for the method.

public record ExampleRecord(
  AReallyLongClassNameThatNecessitatesSplittingOntoMultipleLines a,
  AnotherReallyLongClassNameThatNecessitatesSplittingOntoMultipleLines b
) {
  public AReallyLongClassNameThatNecessitatesSplittingOntoMultipleLines abc(
    AReallyLongClassNameThatNecessitatesSplittingOntoMultipleLines b,
    AnotherReallyLongClassNameThatNecessitatesSplittingOntoMultipleLines c
  ) {
    return b;
  }
}

It seems like it should either complain about both or neither. I’d prefer neither.

SonarSource 7.4.0.60471
SonarQube * 9.7.1 (build 62043)
Java 17.0.4

Hey there.

You’re right, this is a false-positive! It’s tracked here ([SONARJAVA-4393] - Jira) and will be fixed as a part of SonarQube v10.0

Hey, this seems to still be happening in some cases. Here are some more false positives from my code:

// If I remove the type parameters, the warning goes away
public record Batch<E, L>(
    List<E> elements,
    @Nullable L lastElement
) { // <- Sonar complains about this one
  // If I remove this method, the warning goes away
  public boolean isEmpty() {
    return elements.isEmpty();
  }
}

and

public record SomeRecord(Integer value) {

  public SomeRecord(String id) { // <- Sonar complains about this one
    this(0);
  }

  // Removing this field makes the warning go away
  public static final String EXAMPLE = "example";
}

and

public record OuterRecord(String value) {

  public String getThing() { // <- Sonar complains about this one
    return null;
  }

  // Removing this record declaration makes the warning go away
  private record InnerRecord(int value) {}
}

Hey @lbenedetto

Welcome back. What version of SonarQube are you using now?

server: v10.6 (92116)
plugin: 10.11.1.79663

Thanks. I think you’re running into a known FP which you can track here: SONARJAVA-4633