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.

2
  • Does this help: stackoverflow.com/questions/39109228/… ? Alternatively, couldn't you just turn into the SQ user interface and ignore that warning there for that one file? Commented May 25, 2018 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. Commented May 25, 2018 at 19:44

1 Answer 1

0
@SuppressWarnings("squid:S2095") 

This is how I ended up handling that error.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.