This is the mail archive of the java-discuss@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Is serialization broken?


On Fri, 26 Jan 2001, Barnet Wagman wrote:

> I'm getting an erroneous ClassCastException deserializing an object with
> gcj,  gcc version 2.97 20010117 (experimental).
> 
> With the test program SerTest.java (below)...

Well, it seems that java.io.DataInputStream.readInt is throwing an
EOFException because it is mistakenly reading some negative data to mean
EOF.  I was able to jump past the check for the negative value in the
debugger and the program ran to completion just fine.


Breakpoint 2, java.util.HashMap.readObject (this=@8101fc8, s=@8086400)
    at /home/warrenl/egcs/libjava/java/util/HashMap.java:639
639         s.defaultReadObject();
(gdb) n
641         int capacity = s.readInt();
(gdb) 
642         int len = s.readInt();
(gdb) s
java.io.ObjectInputStream.readInt (this=@8086400)
    at /home/warrenl/egcs/libjava/java/io/ObjectInputStream.java:651
651         return this.dataInputStream.readInt ();
(gdb) 
java.io.DataInputStream.readInt (this=@8066f00)
    at /home/warrenl/egcs/libjava/java/io/DataInputStream.java:293
293         int a = in.read();
(gdb) n
294         int b = in.read();
(gdb) 
295         int c = in.read();
(gdb) 
296         int d = in.read();
(gdb) 
297         if (d < 0)
(gdb) p d
$6 = -24
(gdb) l
292       {
293         int a = in.read();
294         int b = in.read();
295         int c = in.read();
296         int d = in.read();
297         if (d < 0)
298           throw new EOFException();
299         
300         return (((a & 0xff) << 24) | ((b & 0xff) << 16) |
301                 ((c & 0xff) << 8) | (d & 0xff));
(gdb) 

It'll take a bit more poking around to see how to properly avoid that < 0
check (that'll have to wait till at least after I've had some sleep ;-).
--warrenl


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]