0

I have a method that initializes a Session object (Cassandra Session, which according to best practices should be shared across application threads as it is quite expensive to initialize one) and returns it back to the caller. Sonarqube suggests closing my Session object in finally block or by using try-with-resources construct.

It doesn't make sense to do it my case as a session should be closed only when the application is shutting down.

Such check makes sense only if my resource should be closed immediately after usage, like connection, file, etc.

How do I get rid of that type of error, please advise.

Ihor M.
  • 2,728
  • 3
  • 44
  • 70
  • Does this help: https://stackoverflow.com/questions/39109228/how-can-we-ignore-some-sonarqube-rules-in-java ? Alternatively, couldn't you just turn into the SQ user interface and ignore that warning there for that one file? – GhostCat May 25 '18 at 19:41
  • Yes, I guess I can always ignore a rule, I was thinking maybe there is a better way to handle such case. – Ihor M. May 25 '18 at 19:44

1 Answers1

0
@SuppressWarnings("squid:S2095")

This is how I ended up handling that error.

Ihor M.
  • 2,728
  • 3
  • 44
  • 70