In our code base we get Sonar reports violation for rule squid:S2095 on code like the following:
PreparedStatement ps = null;
try {
ps = connection.prepareStatement(DML);
ps.setString(1, externalDeviceId);
ps.setInt(2, internalDeviceId);
ps.execute();
return ps.getUpdateCount() > 0;
} finally {
Utilities.close(ps);
}
with Utilities.close implemented as
public static final void close(final AutoCloseable ac) {
if(ac != null) {
try {
ac.close();
} catch(Exception e) {
}
}
}
Is there a way to avoid these false positives?