Skip to content

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

Closed

Conversation

Pankraz76
Copy link

@Pankraz76 Pankraz76 commented Jun 13, 2025

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.

need to be cautions with this:

image

Copy link

quarkus-bot bot commented Jun 13, 2025

/cc @brunobat (opentelemetry), @radcortez (opentelemetry)

Copy link

quarkus-bot bot commented Jun 13, 2025

Thanks for your pull request!

Your pull request does not follow our editorial rules. Could you have a look?

  • title should preferably start with an uppercase character (if it makes sense!)

This message is automatically generated by a bot.

@Pankraz76
Copy link
Author

assuming 90 LOC less boilerplate is an simple decision to make. @geoand

happy travelling.

@Pankraz76 Pankraz76 force-pushed the use-try-with-resources-statement branch from 14f48ad to 6228667 Compare June 13, 2025 09:11
@Pankraz76 Pankraz76 marked this pull request as ready for review June 13, 2025 09:15

This comment has been minimized.

@Pankraz76
Copy link
Author

will SOC.

@Pankraz76 Pankraz76 closed this Jun 15, 2025
@quarkus-bot quarkus-bot bot added the triage/invalid This doesn't seem right label Jun 15, 2025
if (serverSocket != null) {
try {
serverSocket.close();
} catch (IOException e) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this catch is missing.

Object result = invocationContext.proceed();
instrumenter.end(currentSpanContext, methodRequest, null, null);
return result;
} catch (Throwable t) {
instrumenter.end(currentSpanContext, methodRequest, null, t);
throw t;
} finally {
if (currentScope != null) {
currentScope.close();
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant