rajesh
rajesh

Reputation: 3407

Close Resource violation in Sonar

In my Dao classes, for closing db resources I have written a small function which takes in ResultSet, Connection and Statement objects and closes it.

I call this from finally block of each DB access method that I have. But Sonar is showing these as violations like:

Ensure that resources like this Statement object are closed after use

Is there any way to let Sonar know that these are handled?

Profile used is 'Sonar Way'

Upvotes: 2

Views: 8023

Answers (1)

This rule is brought by PMD into Sonar, and it is quite basic: it just checks if there's a "myResource.close()" call in the finally block. Full stop. If you're extensively using your "small function", then you should probably consider deactivating this rule as it will generate too many false positives.

You could also try to activate Findbugs rules that may be more intelligent. See those rules on our Sonar demo instance - Nemo.

Upvotes: 5

Related Questions