• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Enum ConstantNotPresentException

 
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When is EnumConstantNotPresentException thrown???



Here the RuntimeException is IllegalArgumentException.
 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Docs
See this says

Uses of Class
java.lang.EnumConstantNotPresentException
No usage of java.lang.EnumConstantNotPresentException

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's really strange. The API documentation for class EnumConstantNotPresentException says:

Thrown when an application tries to access an enum constant by name and the enum type contains no constant with the specified name.


But Enum.valueOf(), which looks up an enum constant by name, throws an IllegalArgumentException instead of an EnumConstantNotPresentException.

I think this is a bug in the Java API.
 
Abhi vijay
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Punit check this out.

web page
[ December 21, 2008: Message edited by: Abhi vijay ]
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But what to see there?

If I have to see valueOf of enum then it is:

valueOf

public static <T extends Enum<T>> T valueOf(Class<T> enumType,
String name)

Throws:
IllegalArgumentException - if the specified enum type has no constant with the specified name, or the specified class object does not represent an enum type
NullPointerException - if enumType or name is null
Since:
1.5



If I have to see EnumConstantNotPresentException

public class EnumConstantNotPresentException
extends RuntimeException

Thrown when an application tries to access an enum constant by name and the enum type contains no constant with the specified name.

Since:
1.5


But when I click on the Use link on this page, see what I got


Uses of Class
java.lang.EnumConstantNotPresentException
No usage of java.lang.EnumConstantNotPresentException

 
Abhi vijay
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just wanted to know when is Enum ConstantNotPresentException thrown?
 
Master Rancher
Posts: 4023
53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, have you looked at the API? You can find EnumConstantNotPresentException here.
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike do you have any concret example for this situation as I have already seen and given this link in my reply. I tried different situation but I am not getting this error.
 
Mike Simmons
Master Rancher
Posts: 4023
53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I should have read all the preceding posts. OK. I think that probably the exception will be thrown if one class refers to an enum value from another class, but then the other class is changed and recompiled so that it no longer contains the referenced enum value. In order for this to work, you don't try to recompile the second class, the one that references the formerly-valid value. You just run its code. If you tried to recompile, you would get a compile error. But if you run the previously-compiled file, the only option is to get a runtime exception or error.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I grepped through the source code of Sun JDK 6 and found only one place where this exception is used: in interface java.lang.reflect.AnnotatedElement. The API documentation for that interface says:

Represents an annotated element of the program currently running in this VM. This interface allows annotations to be read reflectively. All annotations returned by methods in this interface are immutable and serializable. It is permissible for the caller to modify the arrays returned by accessors for array-valued enum members; it will have no affect on the arrays returned to other callers.

If an annotation returned by a method in this interface contains (directly or indirectly) a Class-valued member referring to a class that is not accessible in this VM, attempting to read the class by calling the relevant Class-returning method on the returned annotation will result in a TypeNotPresentException.

Similarly, attempting to read an enum-valued member will result in a EnumConstantNotPresentException if the enum constant in the annotation is no longer present in the enum type.

Finally, Attempting to read a member whose definition has evolved incompatibly will result in a AnnotationTypeMismatchException or an IncompleteAnnotationException.


Note: You do not need to know this for the SCJP exam.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic