Getting java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LBlndItmTmMthd
I need a serious help in this issue. May be its very basic, but, I am not able to figure it out. I have a session EJB with one method which returns an enum array, i.e. BlndItmTmMthd
array. When, I call the method in the client side, it gives me a ClassCastException
.
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LBlndItmTmMthd
While debugging, I have found that the ejb method is correctly returning BlndItmTmMthd
array by calling BlndItmTmMthd.values()
. I am not able to find out the reason. Any idea will be helpful.
Added content from a comment below
AgreementSession.java is the EJB interface which contains the following method declaration:BlndItmTmMthd[] getAllBlendedItemTimingMethods();
AgreementSessionEJB.java is the EJB that implements it.
public BlndItmTmMthd[] getAllBlendedItemTimingMethods() {
BlndItmTmMthd[] blendedItemTmingMethods = BlndItmTmMthd.values();
return blendedItemTmingMethods;
}
开发者_JAVA技巧Now, at the client side, when I invoke the EJB method with the following code:
BlndItmTmMthd[] _timingMethods =
getLoanScheduleSetupSession().getAllBlendedItemTimingMethods();
I get that runtime exception.
The "[L" in your error tells you the problem - Java is failing to cast an array of Objects (that is, an Object[]) to an array of BlndItmTmMthds (a BlndItmTmMthd[]).
Is BlndItmTmMthd really a java.lang.Enum?
Given that the error implies that there is a failure to cast objects of type java.lang.Object to the Enum class, I believe there is a failure in the serialization and deserialization process when the response from the EJB is received at the client.
There are a couple of things that you might want to check:
- Is the Enum class BlndItmTmMthd available in the same classloader, or is it loaded twice?
- Does the generated stub of the EJB contain references to the Enum class or to java.lang.Object?
I assume that you have access to both the server and the client code. To trace down this issue you should insert logging statements of the form
logger.info(array.getClass().getCanonicalName());
at all places on the way from the BlndItmTmMthd
to the Object
. Then you can at least say at which point the conversion happens.
精彩评论