users@glassfish.java.net

Re: Serious problem w/ Glassfish V2 Beta 2 & Wicket

From: <glassfish_at_javadesktop.org>
Date: Thu, 10 May 2007 11:53:28 PDT

I can't speak to the underlying problem, but the "cannot cast" error message, while a bit startling at first glance, is actually giving a bit of information. How can an object of a class not be cast to that class? If the same class definition was loaded by different class loaders. Java considers those to be two completely different class definitions.

Probably the object the code is trying to cast is derived from the class as loaded by one class loader, while a different class loader (I'm not sure whether it's the current thread's context class loader or the class loader that loaded the currently-running class) provides the class to which the code is trying to do the cast.

MyClass myObj = (MyClass) otherObj;

I suspect that otherObj was instantiated using a definition of MyClass loaded by some other class loader so that the cast to [i]this [/i]code's class loader's MyClass definition fails.

That may help a little.

- Tim
[Message sent by forum member 'tjquinn' (tjquinn)]

http://forums.java.net/jive/thread.jspa?messageID=216374