File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Websphere and the fly likes ClasscastException when passing an object between 2 EAR's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "ClasscastException when passing an object between 2 EAR Watch "ClasscastException when passing an object between 2 EAR New topic

ClasscastException when passing an object between 2 EAR's

Johan Vandevenne

Joined: Jun 03, 2001
Posts: 10
I have the following problem. I have a serializable object which I pass between 2 EJB's. These EJB's are located in 2 seperate EAR files. When I pass a Vector of these objects between those 2 beans, I get a ClassCastException in the receiving EJB. I am completely sure that those 2 EAR's have the same version of this class in their classpath's.
Also, an instanceof resturns false, but when I walk through the code with a debugger, I look into the Vector and see that there are indeed objects inside which have the name of the class which I'm trying to cast. So It's really weird.
I use Websphere 5.
Maybe someone has already encountered this problem before, or all sugestions or ideas are welcome...
Johan Vandevenne
[ May 12, 2003: Message edited by: Johan Vandevenne ]
Tao Liu

Joined: Nov 02, 2001
Posts: 13
When did you get ClassCastException? Is it thrown when you cast Vector.get(int) or sth else? It seems a RMI issue.
I got a similar problem when I tried to pass ArrayList across .ear files, but that is because ArrayList uses transient member variables to hold its elements. Vector is a totally different story, it holds its element with this:
protected Object elementData[];
So it's weird unable to use Vector across .ears.
One possible way to avoid ClassCastException is to package the common objects in a separate .jar and put this .jar in a shared directory such as $WAS_ROOT/lib/app. This is also recommeneded in WebSphere InfoCenter.
[ May 14, 2003: Message edited by: Tao Liu ]
[ May 21, 2003: Message edited by: Tao Liu ]
[ May 21, 2003: Message edited by: Tao Liu ]
randal alan

Joined: Jun 14, 2002
Posts: 9
Not sure if this will help but here's some info regarding the ClassCastException. I hope this is useful.
Classloader Mode
Specifies whether the classloader searches in the parent classloader or in the application classloader first to load a class. The standard for JDK classloaders and WebSphere Application Server classloaders is PARENT_FIRST. By specifying PARENT_LAST, your application can override classes contained in the parent classloader, but this action can potentially result in ClassCastException or LinkageErrors if you have mixed use of overridden classes and non-overridden classes.
The options are PARENT_FIRST and PARENT_LAST. The default is to search in the parent classloader before searching in the application classloader to load a class.
SJ Adnams
Ranch Hand

Joined: Sep 28, 2001
Posts: 925
try turning off jit compiler.
denny hau

Joined: May 14, 2003
Posts: 4
An object that is used by 2 EAR can be put into <websphere>/lib/ext. In this case the class that encapsulated by vector.
I think it's because of diffrent classloader mecanishm (as Randal said)
Hopefully it's help...
Tao Liu

Joined: Nov 02, 2001
Posts: 13
With 2 EARs, I can recreate the ClassCastException in WAS 4.0.4 (as in WSAD5), but it's OK (no exception) in WAS 5.0. I make the two configurations equivalent according to WebSphere documentation. Could you please explain why it works on one version but not the other?
Thanks in advance,
The server configurations are set as default:
1) The module visibility of WAS 4.0.4 is J2EE (;
2) The server configuration of WAS 5.0:
Application classloader policy = MULTIPLE;
Application classloder mode = PARENT_FIRST
WAR classloader policy = MODULE
[ May 28, 2003: Message edited by: Tao Liu ]
I agree. Here's the link:
subject: ClasscastException when passing an object between 2 EAR's
It's not a secret anymore!