This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Serialization of empty vector over a socket
- From: Mark Wielaard <mark at klomp dot org>
- To: "Robertson, Jason V" <jason dot v dot robertson at intel dot com>
- Cc: "'java at gcc dot gnu dot org'" <java at gcc dot gnu dot org>
- Date: 21 Jul 2002 17:53:01 +0200
- Subject: Re: Serialization of empty vector over a socket
- References: <0DCC27458EB5D51181840002A507069E0451D18B@orsmsx117.jf.intel.com>
Hi,
On Fri, 2002-07-19 at 23:51, Robertson, Jason V wrote:
> I've got a simple client-server test case where the server listens on a
> socket, accepts a connection, reads in an object, and prints the object's
> toString() representation. The client simply opens a port to the server,
> and sends a 'new Vector()'. The problem is, the server gets a
> NullPointerException in the deserialization process when I compile with gcj
> (from GCC 3.1, Linux).
>
> I tried debugging a little, but I'm not sure if serialization is broken on
> the client, or deserialization on the server. Here's the output I get on
> the server-side, followed by the code. Any ideas?
It seems that our serialization implementation is broken :{
I made a simplified example program from the code you provided
(attached). I tried debugging it a bit and I am not sure where the
NullPointerException comes from. When I link with -static (which gives
nicer stack traces when libgcj is compiled with debugging symbols) then
I get a java.lang.RuntimeException: The SHA algorithm was not found to
use in computing the Serial Version UID for class [Ljava.lang.Object;
I am investigating this further.
Cheers,
Mark
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.IOException;
import java.util.Vector;
public class SerVector
{
public static void main(String[] args)
{
try
{
Vector v = new Vector();
System.out.println(v);
// Turn Vector object into serialized byte array.
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(v);
oos.close();
out.close();
byte[] array = out.toByteArray();
// Turn serialized byte array into Vector object.
ByteArrayInputStream in = new ByteArrayInputStream(array);
ObjectInputStream ois = new ObjectInputStream(in);
Vector inObject = (Vector) ois.readObject();
System.out.println(inObject);
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
catch(ClassNotFoundException cnfe)
{
cnfe.printStackTrace();
}
}
}