Channel should not implement Autoclosable because a channel is expected to stay open. #773
Replies: 4 comments 2 replies
-
I don't think we should do that. All these static code analysers by definition are subjective Nothing in AutoClosable docs suggests that a resource that stays open for a long period of time cannot implement it. Please add an exclusion (I'm sure Sonar allows for that) and move on. |
Beta Was this translation helpful? Give feedback.
-
"Move on." In what use case would Autoclosable be useful for a Channel? GFY |
Beta Was this translation helpful? Give feedback.
-
To wrap this up: we will keep
We will also treat the above GFY comment by @karlnicholas as an intentional insult and apply adequate restrictions to his account for the entire RabbitMQ org. |
Beta Was this translation helpful? Give feedback.
-
The definition of
Being able to use the
Item 9 of Effective Java 3rd edition covers the benefits of I stand by my colleague and suggest you use the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Channel should not implement Autoclosable because a channel is expected to stay open for the duration of the application, if not longer.
I get a SonarLint error for the following code:
Channel channel = connection.createChannel();
==============================================
Resources should be closed
Bug
Blocker
java:S2095
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 otherwise an exception could keep the call from being made. Preferably, when class implements AutoCloseable, resource should be created using "try-with-resources" pattern and will be closed automatically.
Failure to properly close resources will result in a resource leak which could bring first the application and then perhaps the box the application is on to their knees.
Beta Was this translation helpful? Give feedback.
All reactions