luontola / retrolambda

Backport of Java 8's lambda expressions to Java 7, 6 and 5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Backport try-with-resources for Java 6 and below

luontola opened this issue · comments

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.

Included in Retrolambda 1.8.0

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

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?