You should try and reproduce the issue using this version of our Java analyzer (upgrading the plugin), or better yet upgrade to SonarQube v8.5. When using a non-LTS version of SonarQube, it’s best to make sure you’re continuing to upgrade as there are new releases.
Hi,
I updated the plugin to 6.3.2 and rescanned the entire project again but still facing the same false positive again. The prepared statements are closed in finally block but still it is giving issue “Use try-with-resources or close this “PreparedStatement” in a “finally” clause.”.
The issue here is that close() can throw an exception (see signature in javadoc), when this happens, the other close will not be called, ending up with an unclosed resource. If you modify the code to handle the exception, something like:
(or any variation suiting your needs), no issue is raised anymore.
It is correct but quite cumbersome, this is why we also suggest having a look at try-with-resources, to see if it could not simplify your code.