classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [cp-patches] FYI: Fix serialization of Class objects


From: Jeroen Frijters
Subject: RE: [cp-patches] FYI: Fix serialization of Class objects
Date: Thu, 20 Jan 2005 12:45:39 +0100

Mark Wielaard wrote:
> > BTW, I didn't really look at Mark's patch (or rather, I did 
> > but I didn't
> > take enough time to understand it), but I just tried it and 
> > it appears to work fine for a class named "int".
> 
> Yes, that probably will/should work. But as soon as you mix the class
> "int" from the unnamed package with trying to (de)serialize the
> primitive type class of 'int' things will break.

You're right. I just tried this (on the Sun JDK):

    ObjectOutputStream oos = new ObjectOutputStream(new
FileOutputStream("serexc.bin"));
    oos.writeObject(Class.forName("int"));
    oos.writeObject(Integer.TYPE);
    oos.flush();
    oos.close();
    ObjectInputStream ois = new ObjectInputStream(new
FileInputStream("serexc.bin"));
    System.out.println(ois.readObject());
    System.out.println(ois.readObject());

The output is:

    class int
    class int

> I don't think there is any way around that since the class names
> in a serialized stream are just names, not type descriptors. You
> could perhaps try to back up when you notice a type conflict and
> retry with the int.class.

Since Sun doesn't handle it either, I wouldn't bother. Chalk it up to
yet another design flaw in serialization.

Regards,
Jeroen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]