use try-with-resources statement#48364
Closed
Pankraz76 wants to merge 1 commit intoquarkusio:mainfrom
Pankraz76:use-try-with-resources-statement
Closed
use try-with-resources statement#48364Pankraz76 wants to merge 1 commit intoquarkusio:mainfrom Pankraz76:use-try-with-resources-statement
try-with-resources statement#48364Pankraz76 wants to merge 1 commit intoquarkusio:mainfrom
Pankraz76:use-try-with-resources-statement
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. |
Author
|
assuming 90 LOC less boilerplate is an simple decision to make. @geoand happy travelling. |
Pankraz76
commented
Jun 13, 2025
This was referenced Jun 13, 2025
This comment has been minimized.
This comment has been minimized.
Author
Author
|
will SOC. |
Pankraz76
commented
Jun 15, 2025
| if (serverSocket != null) { | ||
| try { | ||
| serverSocket.close(); | ||
| } catch (IOException e) { |
Pankraz76
commented
Jun 15, 2025
| throw t; | ||
| } finally { | ||
| if (currentScope != null) { | ||
| currentScope.close(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)