Skip to content
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

Backport try-with-resources for Java 6 and below #38

Closed
luontola opened this issue Nov 15, 2014 · 3 comments
Closed

Backport try-with-resources for Java 6 and below #38

luontola opened this issue Nov 15, 2014 · 3 comments

Comments

@luontola
Copy link
Owner

Though the try-with-resources statement doesn't introduce any new bytecode instructions, it uses the Throwable.addSuppressed method which was added in Java 7. Possible options for a backport:

  1. Swallow the suppressed exception
  2. Throw the suppressed exception, swallowing the original exception
  3. Print the stack trace of suppressed exceptions
  4. Log the suppressed exceptions

Option 2 is clearly undesirable. I think option 3 would possibly cause lots of unwanted stack traces in the console. Option 4 is what Guava's Closer does.

I think the viable options are 1 and 4.

@luontola
Copy link
Owner Author

Included in Retrolambda 1.8.0

@Mart-Bogdan
Copy link

so what options was used? Are you using logger in any way?

@luontola
Copy link
Owner Author

I used option 1.

It's not using a logger currently, but it would be relatively easy to add support for it (e.g. generate code that does java.util.logging.Logger.getLogger("CurrentClass").log(Level.WARNING, "Suppressed exception", exception)). It could be toggleable using a parameter when running Retrolambda. Does somebody want to have such logging?

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

No branches or pull requests

2 participants