Community
Participate
Working Groups
I tried to compile the example given at the end of the bug 338402 comment 5 and I got: Exception in thread "main" java.lang.VerifyError: Instruction type does not match stack map in method X.main([Ljava/lang/String;)V at offset 165 at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2442) at java.lang.Class.getMethod0(Class.java:2685) at java.lang.Class.getMethod(Class.java:1620) at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:484) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:476) I'll close the bug 338402 as verified and the fix should go into this bug.
Srikanth, please investigate.
The test case is: public class X implements AutoCloseable { public static void main(String [] args) throws XXException, YYException, ZZException { try (X x = new X(); Y y = new Y(); Z z = new Z()) { } catch (XException x) { } catch (YException y) { } catch (ZException z) { } finally { } } public X() throws XException { throw new XException(); } public void close() throws XXException { throw new XXException(); } } class Y implements AutoCloseable { public Y() throws YException { throw new YException(); } public void close() throws YYException { throw new YYException(); } } class Z implements AutoCloseable { public Z() throws ZException { throw new ZException(); } public void close() throws ZZException { throw new ZZException(); } } class XException extends Exception {} class XXException extends Exception {} class YException extends Exception {} class YYException extends Exception {} class ZException extends Exception {} class ZZException extends Exception {} I had to add: throws XXException, YYException, ZZException to the original test case. It fails with JDK7 b141, b142, b143, b144, b145 and b146.
Minimal test case: public class X implements AutoCloseable { public static void main(String[] args) { try (X x = new X();) { } catch (Exception x) { } catch (Throwable y) { } } public void close() { } } Both catch blocks are needed to reproduce -- Under investigation.
Fails with both Sun and IBM JREs.
Released disabled junits: org.eclipse.jdt.core.tests.compiler.regression.TryStatement17Test._test029() org.eclipse.jdt.core.tests.compiler.regression.TryStatement17Test._test030()
Created attachment 199028 [details] Proposed patch + tests Under test.
All Test pass. Released in BETA_JAVA7 branch.
Ayush, please review, TIA. Basically the problem was that when the try block is empty we used to mark the catch blocks as being unreachable. And when we have two or more catch blocks, the goto statement that is needed to prevent falling into a subsequent catch block from a prior catch block is optimized out when the (prior) catch block is unreachable. We should not mark the catch blocks as being unreahable just because the try block is empty - we should also consider whether there are any resources.
Patch looks good
Verified with v20110714-1300.