Bug 21299

Summary: RMI ClassCastException when casting Stub
Product: [Eclipse Project] Platform Reporter: Lautier Teva <teva.lautier>
Component: ResourcesAssignee: Platform-Resources-Inbox <platform-resources-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P5 CC: eclipse
Version: 1.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Lautier Teva CLA 2002-07-08 09:19:46 EDT
I have a ClassCastException when trying to access server stub from RMI on 
eclipse. I have the same problem with Tomcat 3.2 ( 
http://mikal.org/interests/java/tomcat/archive/view?mesg=37681 ) , and this 
bug was corrected in tomcat 3.3.1 ( 
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1883 )

Config :
A plugin having RMI client library
Another plugin using this one, code is

Object o = Naming.lookup("//machine2/MyServer");
// ok
System.out.println("Class=" + o.getClass().getName());
// prints "Class=MyServerImpl_Stub"
// and this class implements MyServer interface
MyServer p = (MyServer ) o;  // exception is raised!!!!

Everything works fine when I put the STUB file (server jar file) in the plugin 
libraries but it is not the best solution.

I thing it is a ClassLoader problem.
thx
Comment 1 John Arthorne CLA 2002-07-08 10:17:52 EDT
This happens when the same class is loaded by two different class loaders.  In 
eclipse, this means you have two different plugins that define the same class.  
In this case, it appears that MyServer.class is located in two different 
plugins.  If this is the case, you need to remove one of them.
Comment 2 John Arthorne CLA 2002-07-23 10:47:21 EDT
Closing.  This happens if the same class is found in two different plugins.  If 
this is not the case, please reopen.
Comment 3 Lautier Teva CLA 2002-07-30 05:00:37 EDT
Jhon Arthorne said

>This happens if the same class is found in two different plugins

This is definitely not the case!
Comment 4 Rafael Chaves CLA 2003-10-01 12:36:57 EDT
As you can see from the Tomcat PR you mentioned, if you don't put the stubs in
the plug-in runtime classpath, the RMI classloader will load them (and the
remote interfaces they implement) from the server. This causes the class cast
exception.

There are two workarounds. One is putting the stubs in your plug-in runtime
classpath (as you did). The other is to set the context classloader to be your
plug-in's classloader before retrieving references to remote objects (see bug 8907).

Closing as duplicate of bug 8907 (you get ClassCastExceptions because you have
specified a security manager). 

*** This bug has been marked as a duplicate of 8907 ***