Bug 159822

Summary: [compiler] non-static access of static field yields unverifiable code
Product: [Eclipse Project] JDT Reporter: Art Dyer <art.dyer>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: philippe_mulet
Version: 3.2.1   
Target Milestone: 3.2.2   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Art Dyer CLA 2006-10-04 19:39:20 EDT
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)
Comment 1 Olivier Thomann CLA 2006-10-04 22:38:12 EDT
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 ***
Comment 2 Maxime Daniel CLA 2007-01-16 02:09:43 EST
Verified for 3.2.2 using build M20070112-1200.
Comment 3 Maxime Daniel CLA 2007-01-17 03:40:22 EST
Released same test case in R3_2_maintenance stream.