FP in S2095: Use try-with-resources or close this "ElasticsearchRestClient" in a "finally" clause

SonarQube version 7.6
Java 1.8

When we use Spring Data ElasticSearch in Spring framework,The lifecycle of a Spring Bean is usually managed by the Spring IOC container。

But sonarQube raise a blocker bug saying “Use try-with-resources or close this “ElasticsearchRestClient” 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 code:

This usage comes from:

Anybody Here?

Hello @tclmcn,

We are aware that this rule could conflict with resources behaving as you described, this is why there is a parameter, enabling you to add a list of the excluded resource types (excludedResourceTypes parameter).

In addition, if you think a bug is clearly a false positive, you could choose to resolve it as such in the UI, to not degrade the grade of the project.

I hope this helps,


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.