[Spread-users] deserialization problem on unix?
Rod Fleischer
rodf at sparta.com
Wed May 14 15:16:13 EDT 2003
Hi,
I'm having a problem with deserialization on a unix machine, in
particular linux (redhat 7.2, 8.0, 9.0) and solaris (2.8). The exact
same code running on a windows xp machine works completely fine. And
I'm positive that it's the same code, because the filesystem with the
code lives on a windows xp machine and is smbmounted onto the unix machines.
The specific details are that I encapsulate a Serializable object in a
SpreadMessage and send it out. The unix side will throw an exception
when it tries to deserialize the object during a call to
SpreadMessage.getObject(). This doesn't make sense to me.
Included below is a trivial example which manifests the problem for me.
A Foo object is created and sent out via the SpreadConnection. A call
to receive() is then made for a message from another client, from which
a Foo object is then extracted from the SpreadMessage and its contents
printed.
Running this test between a windows and a linux machine, the windows
side works flawlessly. The linux side is able to send a message to it
successfully. The linux side, however, throws a ClassNotFoundException
when it attempts to deserialize the Foo object. This strikes me as
rather odd, seeing as how it's being run from the exact same filesystem,
using the exact same .class file, and it just instantiated a Foo object
on its own to send out, thus proving that it DOES know about class Foo.
The output on the linux side is as follows:
[charlie:~/workspace/scng][12:28pm]% /usr/java/bin/java -cp ./classes
com.sparta.network.spread.Foo
Press enter------------------------------
Sending: charlie.columbia.sparta.com
spread.SpreadException: readObject(): java.lang.ClassNotFoundException:
com.sparta.network.spread.Foo
at spread.SpreadMessage.getObject(SpreadMessage.java:566)
at com.sparta.network.spread.Foo.main(Foo.java:62)
I added a couple lines for a FileOutputStream to dump the Serializable
object out to a file when it's written to and read from the socket. The
serialized object from the windows side is identical to what the spread
connection on the linux side received. (verified with linux 'cmp'
command.) The linux side cannot successfully deserialize the object.
Any help would be extremely appreciated, as this is currently a
show-stopper for me.
Thanks very much,
-Rod
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Rod Fleischer Senior Engineer SPARTA, Inc.
410.872.1515.x241 410.872.8079 (fax) rodf at sparta.com
--------------------------------------------------
----------------------------------------- Foo.java
--------------------------------------------------
/*
* Foo.java
*
* Created on May 14, 2003, 11:15 AM
*/
package com.sparta.network.spread;
import spread.*;
import java.io.*;
import java.net.*;
/**
*
* @author rodf
*/
public class Foo implements Serializable {
Serializable data = null;
/** Creates a new instance of Crap */
public Foo( Serializable ser ) {
data = ser;
}
public Object getData() {
return data;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
String localhost = InetAddress.getLocalHost().getHostName();
Foo foo = new Foo( localhost );
SpreadConnection connection = new SpreadConnection();
connection.connect( InetAddress.getByName("moonblade"), 0,
localhost, false, false );
SpreadGroup group = new SpreadGroup();
group.join( connection, "testgroup" );
SpreadMessage spmsg = new SpreadMessage();
spmsg.addGroup( group );
spmsg.setFifo();
spmsg.setSelfDiscard( true );
spmsg.setObject( foo );
System.out.println( "Press enter ----------------------" );
System.in.read();
System.out.println( "Sending: " + localhost );
connection.multicast( spmsg );
spmsg = connection.receive();
Foo recvd = (Foo) spmsg.getObject();
System.out.println( "Received: "+(String)recvd.getData() );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
More information about the Spread-users
mailing list