In my project recently I've encountered code that compiles perfectly fine, however is very surprising to any reader and should not pass static analysis.
class BracketsAfterMethodSignature {
Object emptyArray()[] {
return new Object[]{};
}
}
We use Checkstyle, PMD, ErrorProne and SonarLint but none of these tools complains on such construct. Is there any rule that could be enabled or tool that can be used to prevent such code?
Apparently Checkstyle's ArrayTypeStyle doesn't include such case.
EDIT
I was running static analysis on a file with .groovy
extension and SonarLint said that this code is fine. After changing extension to .java it detected the issue. And indeed after update to 8.18 Checkstyle also spots it correctly.