A false positive about rule RSPEC-2095

Hi, I found a false positive in SonarQube 9.5.0, please read the following code example.

SonarQube reports that in is not closed in finally branch. However, @lombok.Cleanup can generate related statements to help us close in. Hence, I think this is a false positive.

public static void main(String[] args) throws IOException {
    @Cleanup
    InputStream in = new FileInputStream(args[0]);  // a false positive   
    byte[] b = new byte[10000];
    while (true) {
        int r = in.read(b);
        if (r == -1)
            break;
    }
}
1 Like

Hello @Belle ,

Thank you very much for reporting.
I created a ticket for the issue.

Great news! The ticket has been implemented, and now we should correctlly handle lombok @Cleanup annotations. This update should be soon available on SonarQube for Cloud and released with SonarQube Server 10.9.