tags:

views:

58

answers:

4
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassCastException: java.io.ObjectStreamClass cannot be cast to java.lang.String
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at com.nxl.smssession.SessionRMI.<init>(SessionRMI.java:33)
at com.nxl.smssession.Main.main(Main.java:33)
Caused by: java.lang.ClassCastException: java.io.ObjectStreamClass cannot be cast to java.lang.String

Can someone explain why this error is happening

This is happening when i am doing RMI Bind Operation

This problem is happening on SOLARIS System only, it is working fine in windows and Linux

Here is the code which generates this error

public SessionRMI(String servicename) throws AlreadyBoundException {
SessionImpl service = new SessionImpl();
try {
logger.debug("Publishing the SMS Session endpoint "+servicename);
SessionIface stub = (SessionIface) UnicastRemoteObject.exportObject(service, 0);
Registry registry = LocateRegistry.getRegistry(); registry.rebind(servicename, stub);
logger.debug("SMS Session endpoint published successfully "+servicename);
} catch (RemoteException ex) {
logger.error(ex.toString()); ex.printStackTrace();
}
}

Thanks in advance

A: 

Please give us the problematic code at (SessionRMI.java:33) so we can examine it.

Without additional info i can only say:

Intead of casting try Object.toString();

ObjectStreamClass osc = new ObjectStreamClass();

String str1 = (String)osc; // Throws ClasCastException

String str2 = osc.toString(); // always works if osc is not null
krmby
A: 

It looks like you have a remote method that expects a String argument, but instead you give it a java.io.ObjectStreamClass instead. This will of course raise an UnmarshalException.

You should carefully examine your RMI bind operation attempt and ensure that you are trying to invoke the right method, and you're providing the right arguments wherever needed. Consult the documentation to confirm what the String argument is supposed to represent, and provide it accordingly.

References

polygenelubricants
A: 

It's the stub itself that can't be deserialized. I would double-check the generation of your stub class, and make sure you don't have any old .class files lying around on the Solaris box.

EJP
A: 

Thanks for the help guys.

I solved the problem myself.

It seems like the rmiregistry was not starting up on the solaris system as it does in windows and linux.

I had to manually start it from within the code itself.

Vivek Mehra