Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 350579 - [1.7][compiler] VerifyError running example from bug 338402 comment 5
Summary: [1.7][compiler] VerifyError running example from bug 338402 comment 5
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.7.1   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-28 09:22 EDT by Olivier Thomann CLA
Modified: 2011-08-05 02:54 EDT (History)
2 users (show)

See Also:
amj87.iitr: review+


Attachments
Proposed patch + tests (5.12 KB, patch)
2011-07-04 03:22 EDT, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2011-06-28 09:22:48 EDT
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.
Comment 1 Olivier Thomann CLA 2011-06-28 09:23:01 EDT
Srikanth, please investigate.
Comment 2 Olivier Thomann CLA 2011-06-28 11:18:42 EDT
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.
Comment 3 Srikanth Sankaran CLA 2011-06-28 13:46:30 EDT
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.
Comment 4 Srikanth Sankaran CLA 2011-07-04 01:37:40 EDT
Fails with both Sun and IBM JREs.
Comment 5 Srikanth Sankaran CLA 2011-07-04 02:23:04 EDT
Released disabled junits:

org.eclipse.jdt.core.tests.compiler.regression.TryStatement17Test._test029()
org.eclipse.jdt.core.tests.compiler.regression.TryStatement17Test._test030()
Comment 6 Srikanth Sankaran CLA 2011-07-04 03:22:02 EDT
Created attachment 199028 [details]
Proposed patch + tests

Under test.
Comment 7 Srikanth Sankaran CLA 2011-07-04 04:58:43 EDT
All Test pass. Released in BETA_JAVA7 branch.
Comment 8 Srikanth Sankaran CLA 2011-07-04 05:03:54 EDT
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.
Comment 9 Ayushman Jain CLA 2011-07-05 04:32:16 EDT
Patch looks good
Comment 10 Deepak Azad CLA 2011-07-19 08:55:02 EDT
Verified with v20110714-1300.