A DESCRIPTION OF THE PROBLEM :
The JavaDoc for java.lang.EnumConstantNotPresentException states:
"Thrown when an application tries to access an enum constant by name and the enum type contains no constant with the specified name"
A reasonable conclusion drawn from this sentence is that this exception will be thrown by java.lang.Enum.valueOf in case an invalid enum name is supplied.
This conclusion is wrong, since EnumConstantNotPresentException is used solely to indicate absent enum values for value-returning methods of Java Annotation classes.
(Which raises another question: Why is this exception declared in package java.lang?)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
"Thrown when an application tries to access an enum constant through an Annotation and the enum constant used by the annotated element is no longer present in the application."
ACTUAL -
"Thrown when an application tries to access an enum constant by name and the enum type contains no constant with the specified name"
URL OF FAULTY DOCUMENTATION :
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/EnumConstantNotPresentException.html
The JavaDoc for java.lang.EnumConstantNotPresentException states:
"Thrown when an application tries to access an enum constant by name and the enum type contains no constant with the specified name"
A reasonable conclusion drawn from this sentence is that this exception will be thrown by java.lang.Enum.valueOf in case an invalid enum name is supplied.
This conclusion is wrong, since EnumConstantNotPresentException is used solely to indicate absent enum values for value-returning methods of Java Annotation classes.
(Which raises another question: Why is this exception declared in package java.lang?)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
"Thrown when an application tries to access an enum constant through an Annotation and the enum constant used by the annotated element is no longer present in the application."
ACTUAL -
"Thrown when an application tries to access an enum constant by name and the enum type contains no constant with the specified name"
URL OF FAULTY DOCUMENTATION :
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/EnumConstantNotPresentException.html
- relates to
-
JDK-6548433 (enum spec) java.lang.Enum docs should explain about values() and valueOf(String)
- Resolved
-
JDK-6327048 Enum javadoc could link to JLS
- Resolved