Bug 126091 - [1.5][compiler] Java compiler generates extra field for enums with abstract methods
Summary: [1.5][compiler] Java compiler generates extra field for enums with abstract m...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.2 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-01 15:43 EST by Norbert Kuck CLA
Modified: 2006-02-15 09:34 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 Norbert Kuck CLA 2006-02-01 15:43:00 EST
The Eclipse Java compiler generates an ENUM$VALUES field
even for anonymous enum constant value classes (those
that result from enum constants with class bodies).
Only the (abstract) enum class actually requires an
ENUM$VALUES field in this case - the field in the 
(derived) enum constant class is invisible and thus 
unnecessary. 

The following test class:
  public enum WithMethods {
    VALUE {
      void foo() {};
    };
    abstract void foo();
  }

results in two class files being generated: WithMethods.class
(for the abstract enum class) and WithMethods$1.class (for the
derived enum constant "VALUE" because it has a class body).

Invoking "javap -private" on these two classes yields the 
following results:

Correct:
  public abstract class WithMethods extends java.lang.Enum{
    public static final WithMethods VALUE;
    private static final WithMethods[] ENUM$VALUES;
    static {};
    private WithMethods(java.lang.String, int);
    abstract void foo();
    public static final WithMethods[] values();
    public static final WithMethods valueOf(java.lang.String);
    WithMethods(java.lang.String, int, WithMethods);
  }

Does not need ENUM$VALUES:
  final class WithMethods$1 extends WithMethods{
    private static final WithMethods$1[] ENUM$VALUES;
    WithMethods$1(java.lang.String, int);
    void foo();
  }

Tested on Eclipse Version: 3.1.2 (Build id: M20060118-1600). 
Earlier versions have the same bug.
Comment 1 Olivier Thomann CLA 2006-02-02 11:40:45 EST
Fixed and released in HEAD.
Added regression test org.eclipse.jdt.core.tests.compiler.regression.EnumTest.test127
Comment 2 Olivier Thomann CLA 2006-02-02 11:40:55 EST
Fixed
Comment 3 Olivier Thomann CLA 2006-02-02 11:42:48 EST
Backported to 3.1.x.
Same regression test added.
Comment 4 David Audel CLA 2006-02-15 09:34:51 EST
Verified for 3.2 M5 using build I20060215-0010