Bug 78321 - Problem with Enum.values in static initializer.
Summary: Problem with Enum.values in static initializer.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 81454 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-11-10 13:36 EST by Robert Konigsberg CLA
Modified: 2004-12-16 15:25 EST (History)
1 user (show)

See Also:


Attachments
Apply on HEAD (4.61 KB, patch)
2004-11-10 15:04 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Konigsberg CLA 2004-11-10 13:36:13 EST
Given the following code:

public enum TestEnum
{
  FIRST,
  SECOND,
  THIRD;

  static {
    System.out.println("static");
    try {
      System.out.println("values=" + values());
      for (TestEnum t : values()) {
        System.out.println(" enum: " + t);
      }
    } catch(Exception e) {
      System.out.println(e);
      e.printStackTrace();
    }
  }

  TestEnum() {
    System.out.println("TestEnum ctor");
  }

  public static void main(String[] args) {
  }
}


I can compile it and run it on a Linux workstation, and it produces the
following output: 

TestEnum ctor
TestEnum ctor
TestEnum ctor
static
values=[LTestEnum;@15ff48b
 enum: FIRST
 enum: SECOND
 enum: THIRD


That's good.

However, when I run this on Eclipse 3.1M3 on WinXP, I get a NullPointerException
 within values() on the line for (TestEnum t : values())
Comment 1 Olivier Thomann CLA 2004-11-10 14:41:59 EST
The bug is that the static initializer is processing user code first instead of
generating the static init of the ENUM$VALUES synthetic field.
Comment 2 Olivier Thomann CLA 2004-11-10 15:04:11 EST
Created attachment 15783 [details]
Apply on HEAD

Proposed patch to generate all enum constants and the values synthetic field
first and then the remaining part of the clinit.
Comment 3 Olivier Thomann CLA 2004-11-10 17:34:34 EST
Fixed and released in HEAD.
Regression test added.
Comment 4 Jerome Lanneluc CLA 2004-12-14 09:35:50 EST
Verified that this test case can be compiled and run on Win XP using I200412140010.
Comment 5 Olivier Thomann CLA 2004-12-16 15:25:35 EST
*** Bug 81454 has been marked as a duplicate of this bug. ***