Bug 156591 - [1.5][compiler] constant-specific methods in enum cannot be abstract
Summary: [1.5][compiler] constant-specific methods in enum cannot be abstract
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2.2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 166866 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-09-07 15:50 EDT by Irina Marudina CLA
Modified: 2007-01-15 12:56 EST (History)
3 users (show)

See Also:


Attachments
Proposed patch (4.78 KB, patch)
2006-09-08 06:05 EDT, Philipe Mulet CLA
no flags Details | Diff
Better patch (7.46 KB, patch)
2006-09-08 06:41 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Irina Marudina CLA 2006-09-07 15:50:46 EDT
According to the J2SE Specification : "It is a compile-time error for the class body of an enum constant to declare an abstract method.", but no error is reported in this case.

Example:

public enum Operation {
  PLUS   { double eval(double x, double y) { return x + y; } },
  MINUS  { abstract double eval(double x, double y); };

  abstract double eval(double x, double y);
}

When trying to use the class, the following exception appears in the console :

Exception in thread "main" java.lang.ClassFormatError: Illegal class modifiers in class enumtest/Operation: 0x4412
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
	at enumtest.Main.main(Main.java:22)
Comment 1 Olivier Thomann CLA 2006-09-07 19:57:22 EDT
Not only we don't detect this case, but we also don't detect abstract method not implemented.
public enum X {
  PLUS   { double eval(double x, double y) { return x + y; } },
  MINUS  { abstract void eval2(Object x, Object y); };

  abstract double eval(double x, double y);
  public static void main(String[] args) {}
}


In this case, we don't detect that eval2 is abstract and we don't detect that eval is not implemented for MINUS.
X ends up being abstract and this is also illegal.
See JLS3 8.1.1.1
Comment 2 Philipe Mulet CLA 2006-09-08 06:05:40 EDT
Created attachment 49701 [details]
Proposed patch

3.3 patch
Comment 3 Philipe Mulet CLA 2006-09-08 06:41:33 EDT
Created attachment 49705 [details]
Better patch

Improved patch, which also clarifies the AccFinal positionning.
In the past, it was always set, and cleared during enum constant checkAndSetModifiers, which could allow for some discrepancy in the meantime.
Comment 4 Philipe Mulet CLA 2006-09-08 09:12:06 EDT
Added EnumTest#test138-141.
Released for 3.3M2 (HEAD)

Will queue the change as well for 3.2.2 (too late for 3.2.1)
Comment 5 Frederic Fusier CLA 2006-09-18 12:55:35 EDT
Verified for 3.3 M2 using build I20060918-0010.
Comment 6 Philipe Mulet CLA 2006-09-28 10:34:11 EDT
Released for 3.2.2
Comment 7 Olivier Thomann CLA 2006-12-05 22:11:06 EST
*** Bug 166866 has been marked as a duplicate of this bug. ***
Comment 8 Frederic Fusier CLA 2007-01-15 04:07:55 EST
Reopen for verification
Comment 9 Frederic Fusier CLA 2007-01-15 04:10:30 EST
(In reply to comment #6)
> Released for 3.2.2
> 

Comment 10 Eric Jodet CLA 2007-01-15 06:51:41 EST
verified for 3.2.2 using build M20070112-1200