Object serialization problems about ObjectInputStream, part 1:
Consider read (...) here:
public int read (byte data[], int offset, int length) throws IOException
{
if (this.readDataFromBlock)
{
- if (this.blockDataPosition + length >= this.blockDataBytes){
+ if (this.blockDataPosition + length > this.blockDataBytes){ <- Comment 1
? int remain = this.blockDataBytes - this.blockDataPosition;
? if(remain != 0){
? System.arraycopy (this.blockData, this.blockDataPosition,
? data, offset, remain);
? offset += remain;
? length -= remain; <- Comment 2
}
readNextBlock ();
}
System.arraycopy (this.blockData, this.blockDataPosition,
data, offset, length);
+ this.blockDataPosition += length; <- Comment 3
return length;
}
else
return this.realInputStream.read (data, offset, length);
}
Comment 1:
when "this.blockDataPosition + length == this.blockDataBytes", that means the
data
in block is just enough for read, readNextBlock() shouldn't be invoked, otherwise it
will
read more unmeaningful data into block which might be object data that must be read
by realInputStream. So we should use ">" instead of ">=" here. In fact according to
implementation, the following is also ok here:
if (this.blockDataPosition == this.blockDataBytes){ ... ...
Comment 2:
This patch(beginning with '?' needn't be added actually, because implementation
here
won't lead to such a scenario (a read will across two blocks), but in general it seems
necessary.
Comment 3:
When data in block is read here, blockDataPosition pointer should be updated.
_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath