Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 364008

Summary: VerifyError with nested try-with-resources
Product: [Eclipse Project] JDT Reporter: Frank Ulbricht <frank>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: VERIFIED DUPLICATE QA Contact:
Severity: critical    
Priority: P3 CC: frank, satyam.kandula, srikanth_sankaran
Version: 3.7.1   
Target Milestone: 3.6.2+J7   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Frank Ulbricht CLA 2011-11-17 04:43:34 EST
Build Identifier: 20110916-0149

If you compile and run this class with the Eclipse 3.7.1 compiler level 1.7:

public class Bug {

  public static void main(final String[] args) throws IOException {
    byte[] data;
    try (final ByteArrayOutputStream os = new ByteArrayOutputStream();
         final FileOutputStream out = new FileOutputStream("test.dat")) {
      data = os.toByteArray();
    }
  }
}

you will get this error:

Exception in thread "main" java.lang.VerifyError: Inconsistent stackmap frames at branch target 123 in method Bug.main([Ljava/lang/String;)V at offset 58
	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)

The problem disappears if you do one of the following:
1. remove "final FileOutputStream out = new FileOutputStream("test.dat")"
2. remove "data = os.toByteArray()"
3. change to "byte[] data = null;"
4. use the external compiler from Oracle JaJDK 1.7.0_01

Reproducible: Always

Steps to Reproduce:
1. Compile the class with Eclipse
2. Execute
Comment 1 Srikanth Sankaran CLA 2011-11-17 04:58:30 EST
Most likely a dup of https://bugs.eclipse.org/bugs/show_bug.cgi?id=361053.
Bug 361053 is targetted for 3.8 M4 and the fix will be available for 3.7.2.
Comment 2 Srikanth Sankaran CLA 2011-11-17 07:17:10 EST
Is the same as bug 361053, carried over the test case from here to there
to add a junit.

*** This bug has been marked as a duplicate of bug 361053 ***
Comment 3 Satyam Kandula CLA 2011-12-06 06:35:39 EST
Verified for 3.8M4 using build I20111202-0800
Comment 4 Satyam Kandula CLA 2012-01-19 01:03:30 EST
Verified for 3.7.2RC2 using build M20120118-0800