ARM and repeating exceptions

Joseph Darcy joe.darcy at oracle.com
Tue May 22 16:41:24 PDT 2012


Hello Aleksey,

The semantics of the try-with-resources statement are defined in the 
Java Language Specification:

     
http://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.20.3

Any changes to the semantics of try-with-resources would need to be done 
in the context of a Java SE platform release, such as Java SE 8, and not 
just as a javac change.

That said, I would not support altering the try-with-resources 
desugaring to support this use case.  One exception should be at most 
the cause of XOR suppressed by another.

Cheers,

-Joe

On 5/22/2012 3:07 AM, Aleksey Shipilev wrote:
> Hi,
>
> There is some understandable, but still weird behavior in ARM. Should
> the code cache or throw the same exception on some op(), and close(),
> then ARM block will throw IllegalArgumentException. The minimal test
> case is [1]. I think it can be fixed with simple fix in javac
> desugaring scheme, placing additional check if exception from close()
> is actually the original exception, and not trying to suppress it.
>
> Thanks,
> Aleksey.
>
> [1]
>
> import java.io.IOException;
>
> public class ArmTest {
>
>      // fails with IllegalArgumentException at Throwable.addSuppressed()
>      public static void main(String[] args) {
>          try (MyAutoCloseable worker = new MyAutoCloseable()) {
>              worker.doWork();
>          } catch (IOException e) {
>              throw new IllegalStateException("Chained", e);
>          }
>      }
>
>      private static class MyAutoCloseable implements AutoCloseable {
>          private static final IOException EXCEPTION = new IOException();
>          public void doWork() throws IOException { throw EXCEPTION; }
>          public void close() throws IOException { throw EXCEPTION; }
>      }
> }



More information about the compiler-dev mailing list