Community
Participate
Working Groups
Accessing a static field in a non-static way can produce code that causes a VerifyError (Inconsistent stack height). public class NonStaticAccessToStatic { public static String s; public static void main(String[] args) throws Throwable { if (args.length == 0) { Class c = Class.forName("NonStaticAccessToStatic"); // The object returned by newInstance is left on the stack even // though it is not needed to access field s. String x = ((NonStaticAccessToStatic) c.newInstance()).s; System.out.println(x); } // At this point the stack depth is 1 if the conditional was true, // but 0 if it was false. System.out.println(); } } C:\temp> java NonStaticAccessToStatic java.lang.VerifyError: (class: NonStaticAccessToStatic, method: main signature: ([Ljava/lang/String;)V) Inconsistent stack height 1 != 0 Exception in thread "main" C:\temp> java -version java version "1.5.0_06" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05) Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
This is fixed in HEAD. Closing as dup of bug 159654 since v_715 + fix for 159654 passes the test case, but v_715 alone fails. This failed with v_715 in compliance 1.5 and 1.6. Regression test added in org.eclipse.jdt.core.tests.compiler.regression.CastTest#test044. *** This bug has been marked as a duplicate of 159654 ***
Verified for 3.2.2 using build M20070112-1200.
Released same test case in R3_2_maintenance stream.