Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6378701

(enum) Unclear purpose of EnumConstantNotPresentException

XMLWordPrintable

    • b71
    • x86
    • windows_xp

      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

            darcy Joe Darcy
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: