JDK-5011089 : javac allows programmer to directly subclass the class 'Enum'.
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2004-03-10
  • Updated: 2004-03-10
  • Resolved: 2004-03-10
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 03/10/2004


FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux localhost.localdomain 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686
i386 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
It is possible for a programmer to declare a class that extends the class
java.lang.Enum. The javadoc for the sole constructor says that it is not possible for programmers to call that method directly; it is only for use by code emitted by the compiler. Very specifically, whilst java.lang.Enum can not be final, as the compiler generates code that extends it, it should not be possible for a programmer to extend java.lang.Enum directly in code.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
see code example.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An error message from the compiler along the lines of 'it is illegal to subclass
java.lang.Enum directly'.

ACTUAL -
javac compiles the code with no error message.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
// Can be a top-level or inner class:
public class EnumExtend extends Enum {
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Do not subclass java.lang.Enum.
(Incident Review ID: 242871) 
======================================================================

Comments
EVALUATION The javadoc on a class is its contract, not a language rule. In this case the programmer is violating the contract of java.lang.Enum. There is no specified behavior when a class' contract is violated. Having said all that, the latest draft of the Enum specification does forbid this use as a separate change in the specification. ###@###.### 2004-03-10
10-03-2004