[patch for] Re: Is serialization broken?

Bryce McKinlay bryce@albatross.co.nz
Fri Jan 26 22:02:00 GMT 2001


Warren Levy wrote:

> That may help but I think that ObjectInputStream.read() is the real
> problem.

Turns out that there were bugs in both the read() varients of ObjectInputStream.

I was seeing the second readInt() call in HashMap.readObject return 1535 which was
not the value that the second writeInt() call wrote - it should be 1000. When
HashMap's readObject() attempted to read past the end of its data, readObject
threw an "Invalid marker on stream" IOException because it sees a TC_ENDBLOCKDATA,
which is not handled by the marker switch. Further, useful exception information
is not propogated across the reflection invocation of readObject() because
callReadMethod() essentially ignores InvocationTargetException, making the problem
difficult to identify.

This patch fixes the bugs in both read() methods, and modifies
callReadMethod()/callWriteMethod() to rethrow the target's exception if possible.

The test cases now passes with either of the DataInputStream implementations. I'm
checking this in.

regards

  [ bryce ]




More information about the Java-patches mailing list