Mon, 02 Aug 2010 13:35:39 -0700
6971877: Project Coin: improve semantics of suppressed exceptions in try-with-resources
Reviewed-by: jjb
darcy@609 | 1 | /* |
darcy@609 | 2 | * @test /nodynamiccopyright/ |
darcy@609 | 3 | * @bug 6911256 6964740 6965277 |
darcy@609 | 4 | * @author Maurizio Cimadamore |
darcy@609 | 5 | * @summary Check that resources of an intersection type forces union of exception types |
darcy@609 | 6 | * to be caught outside twr block |
darcy@609 | 7 | * @compile/fail/ref=TwrIntersection02.out -XDrawDiagnostics TwrIntersection02.java |
darcy@609 | 8 | */ |
darcy@609 | 9 | |
darcy@609 | 10 | class TwrIntersection02 { |
darcy@609 | 11 | |
darcy@609 | 12 | static class Exception1 extends Exception {} |
darcy@609 | 13 | static class Exception2 extends Exception {} |
darcy@609 | 14 | |
darcy@609 | 15 | |
darcy@609 | 16 | interface MyResource1 extends AutoCloseable { |
darcy@609 | 17 | void close() throws Exception1; |
darcy@609 | 18 | } |
darcy@609 | 19 | |
darcy@609 | 20 | interface MyResource2 extends AutoCloseable { |
darcy@609 | 21 | void close() throws Exception2; |
darcy@609 | 22 | } |
darcy@609 | 23 | |
darcy@609 | 24 | public void test1() throws Exception1 { |
darcy@609 | 25 | try(getX()) { |
darcy@609 | 26 | //do something |
darcy@609 | 27 | } |
darcy@609 | 28 | } |
darcy@609 | 29 | |
darcy@609 | 30 | public void test2() throws Exception2 { |
darcy@609 | 31 | try(getX()) { |
darcy@609 | 32 | //do something |
darcy@609 | 33 | } |
darcy@609 | 34 | } |
darcy@609 | 35 | |
darcy@609 | 36 | <X extends MyResource1 & MyResource2> X getX() { return null; } |
darcy@609 | 37 | } |