Qube: Community 9.9
The Java rule S2093 nicely reminds me to update older code, that didn’t use try-with-resources. but it should not hit when I open a ByteArrayInputStream, ByteArrayOutputStream, StringReader, StringWriter etc.
Qube: Community 9.9
The Java rule S2093 nicely reminds me to update older code, that didn’t use try-with-resources. but it should not hit when I open a ByteArrayInputStream, ByteArrayOutputStream, StringReader, StringWriter etc.
Yes, sorry. It is 2093.
Oh, and the marker should be placed (at least additionally) to the resource, that needs to be handled. It can be a little hard to find it when the try block is large. Currently the marker is at the next surrounding try, which is random.
Hi,
Thanks for the confirmation. I’ve flagged this for the language experts.
Ann
Hello @mfroehlich,
Thanks for your message. Could you, please, share a code example with me? Is it that you’re using try/finally
with empty finally
or something else?
Best,
Margarita
Hey Margarita,
unfortunately I cannot find the examples in our code. But you’re right. It happens with a try/finally. But doesn’t with a try/catch.
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.reset();
}
finally
{
// Do something...
}
When I stumple across one of our live examples, I will post it here.
Okay, thanks. Will be waiting for the example.