- What language is this for? Java
- Which rule? java:S1105 (Move this left curly brace to the end of previous line of code)
- Why do you believe it’s a false-positive/false-negative?
The left curly brace is already in the end of line - Are you using
- SonarQube Cloud? yes
- SonarQube for IDE? SonarQube for Eclipse 13.2.0
- in connected mode with SonarQube Cloud? yes
- How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
// False positive: the brace already ends the line of the closing parenthesis
record Pair<T>(T first,
T second) { // Noncompliant
}
// Same layout without a type parameter: no issue, as expected
record NamedPair(String first,
String second) {
}
S1105 is raised on the { of Pair, although it is on the same line as the ) that closes the record header. NamedPair has the same layout and gets no issue.
Likely cause: LeftCurlyBraceBaseTreeVisitor.getLastTokenFromSignature(ClassTree) checks typeParameters() before recordCloseParenToken(). For a generic record, the closing > of the type parameters becomes the reference token, and any record header that spans several lines is reported. Checking recordCloseParenToken() before typeParameters() should fix it. LeftCurlyBraceEndLineCheck_record.java has no generic record case yet.
Thanks,
Leib