- SonarQube Enterprise Edition, Version 7.6 (build 21501)
I have the following code:
import com.google.errorprone.annotations.MustBeClosed;
@MustBeClosed
protected Connection createConnection() throws SQLException {
// my method does a couple of other things here so it's not totally pointless
return dataSource.getConnection();
}
SonarQube tells me “Use try-with-resources or close this “Connection” in a “finally” clause”, and declares that this is a “blocker” level bug. I’m not using try-with-resources here because this is a utility method that various other methods will call, and they will all use try-with-resources. If they don’t, then error-prone will complain since the method is annotated with @MustBeClosed.
So I believe that this is a false positive.