SonarQube version 6.7.1
Java 1.8
When we use JdbcTemplate in Spring framework, spring framework’s JdbcTemplate close the PreparedStatement object automatically.
But sonarQube raise a blocker bug saying “Use try-with-resources or close this “PreparedStatement” in a “finally” clause”
Ideally this is not a bug, but due to this false analysis, our project rating is showing E.
Below is the sample code:-
jdbcTemplate.update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
PreparedStatement pst = con.prepareStatement(ADDON_QUERY, new String[] { "id" });
I tried to reproduce your problem with SonarQube 7.9.1 LTS and SonarJava 6.0 and there is not issue raised by 2095.
I guess you have this false-positive issue because you are using an old version of SonarQube. Can you try to upgrade and reproduce your problem with SQ 7.9+?
If you manage to reproduce the problem, that would be great to share a reproducer.