Community
Participate
Working Groups
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
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.
Closing. This happens if the same class is found in two different plugins. If this is not the case, please reopen.
Jhon Arthorne said >This happens if the same class is found in two different plugins This is definitely not the case!
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 ***