Bug 159822 - [compiler] non-static access of static field yields unverifiable code
Summary: [compiler] non-static access of static field yields unverifiable code
Status: VERIFIED DUPLICATE of bug 159654
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.2.2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-04 19:39 EDT by Art Dyer CLA
Modified: 2007-01-17 03:40 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.