No violation reported by "Resources should be closed" squid:S2095

I am using SonarQube 6.7.4 and trying to understand why the rule “Resources should be closed” squid:S2095 is not working the way it is documented.

The documentation says - “Connections, streams, files, and other classes that implement the Closeable interface or its super-interface, AutoCloseable, needs to be closed after use. Further, that close call must be made in a finally block”.

I have left open InputStream, StringWriter and PrintWriter, wrote no finally block, but the rule does not report any violation.

Any hints ?

Hello. Can anybody answer? I am very interested by the subject also… Thank you


Any chance to get an update?

Still waiting for an update.
Can someone acknowledge the issue or provide a comment on why this is happening ?

Hi, sorry for the late reply.

Regarding this is pretty straightforward as this type is excluded from analysis. As documented in the rule description

Could you double-check that those types are not excluded from your sonarqube configuration ? as the rule can be parameterized, I want to make sure this is not due to a misconfiguration.
For your first example I believe it is not raised because the analyzer don’t consider that the resource has been open within this method.

For the printwriter, as the stringwriter is excluded (and thus not open) the behavior seems expected.