-
Notifications
You must be signed in to change notification settings - Fork 3k
use try-with-resources statement
#48364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use try-with-resources statement
#48364
Conversation
|
/cc @brunobat (opentelemetry), @radcortez (opentelemetry) |
|
Thanks for your pull request! Your pull request does not follow our editorial rules. Could you have a look?
This message is automatically generated by a bot. |
|
assuming 90 LOC less boilerplate is an simple decision to make. @geoand happy travelling. |
14f48ad to
6228667
Compare
This comment has been minimized.
This comment has been minimized.
|
will SOC. |
| if (serverSocket != null) { | ||
| try { | ||
| serverSocket.close(); | ||
| } catch (IOException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this catch is missing.
| throw t; | ||
| } finally { | ||
| if (currentScope != null) { | ||
| currentScope.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is save, as equal.
Java 7 introduced the try-with-resources statement. This statement ensures that each resource is closed at the end of the statement. It avoids the need of explicitly closing the resources in a finally block. Additionally exceptions are better handled: If an exception occurred both in the try block and finally block, then the exception from the try block was suppressed. With the try-with-resources statement, the exception thrown from the try-block is preserved.
try-with-resourcesstatement openrewrite/rewrite-static-analysis#591try-with-resourcesstatement inLookupWagonMojoapache/maven#2426need to be cautions with this:
try-with-resourcesstatement spring-projects/spring-framework#35046try-with-resourcesstatement spring-projects/spring-framework#35046 (comment)