Bug 81262

Summary: [Java 5] Verification error when creating anonymous enum subtypes
Product: [Eclipse Project] JDT Reporter: Kai-Uwe Maetzel <kai-uwe_maetzel>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M4   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
source/class files none

Description Kai-Uwe Maetzel CLA 2004-12-15 12:56:03 EST
I200412142000

The attached source/class files cause a VM verification error when executing 
Worker.main.

When commenting lines 5 - 9 and uncommenting line 10 in Day.java, the problem 
goes away.

Pls check whether this is a compiler problem.
Comment 1 Kai-Uwe Maetzel CLA 2004-12-15 12:56:54 EST
Created attachment 16656 [details]
source/class files
Comment 2 Olivier Thomann CLA 2004-12-15 15:05:52 EST
I will investigate.
Comment 3 Olivier Thomann CLA 2004-12-15 15:16:44 EST
Indeed this seems to be a bug in the inner emulation for enum types.
A synthetic constructor is created with the following contents:

  // Method descriptor  #144 (Ljava/lang/String;ILp/Day;)V
  // Stack: 1, Locals: 4
  synthetic p.Day(String arg, int arg, Day arg);
    0  aload_0
    1  invokespecial #43 <Method p/Day.<init>(Ljava/lang/String;I)V>
    4  return
      Line numbers:
        [pc: 0, line: 21]

There is a missing int and string on the stack prior to the invokespecial call.
Comment 4 Olivier Thomann CLA 2004-12-15 15:25:33 EST
Simple test case:`
public enum Day {
	
	MONDAY {
		public void foo() {
		}
	};
	
	private Day() {
	}
	
	public static void main(String[] args) {
	}
}

Error is:
Exception in thread "main" java.lang.VerifyError: (class: Day, method: <init>
signature: (Ljava/lang/String;ILDay;)V) Expecting to find integer on stack
Comment 5 Olivier Thomann CLA 2004-12-15 15:26:11 EST
If you remove the private constructor, it works.
Comment 6 Olivier Thomann CLA 2004-12-15 15:37:21 EST
  // Method descriptor  #56 (Ljava/lang/String;ILDay;)V
  // Stack: 1, Locals: 4
  synthetic Day(String arg, int arg, Day arg);
    0  aload_0
    1  invokespecial #57 <Method Day.<init>(Ljava/lang/String;I)V>
    4  return
      Line numbers:
        [pc: 0, line: 8]

Missing argument on stack.
Comment 7 Philipe Mulet CLA 2004-12-15 15:49:25 EST
Private constructor emulation is not handling enum extra constructor arguments.
Added test: EnumTest#test059.
Fixed
Comment 8 Olivier Thomann CLA 2004-12-15 20:52:58 EST
Verified in 200412160010