Closed LorenzoBettini closed 5 months ago
In Java 8 we have
public ObjectInputStream(InputStream in) throws IOException {
verifySubclass();
bin = new BlockDataInputStream(in);
handles = new HandleTable(10);
vlist = new ValidationList();
serialFilter = ObjectInputFilter.Config.getSerialFilter();
enableOverride = false;
readStreamHeader();
bin.setBlockDataMode(true);
}
protected void readStreamHeader()
throws IOException, StreamCorruptedException
{
short s0 = bin.readShort();
short s1 = bin.readShort();
if (s0 != STREAM_MAGIC || s1 != STREAM_VERSION) {
throw new StreamCorruptedException(
String.format("invalid stream header: %04X%04X", s0, s1));
}
}
public short readShort() throws IOException {
if (!blkmode) {
pos = 0;
in.readFully(buf, 0, 2);
} else if (end - pos < 2) {
return din.readShort();
}
short v = Bits.getShort(buf, pos);
pos += 2;
return v;
}
So readFully
was not used and we didn't get any exception. Probably it's like that also in Java 11.
These two tests always fail when the underlying JVM is Java 17:
org.pitest.pitclipse.runner.io.ObjectStreamSocketTest.writeThrowsException()
org.pitest.pitclipse.runner.io.ObjectStreamSocketTest.readThrowsException()
They mock the socket like that:
The failure is when we call
objectSocket = ObjectStreamSocket.make(underlyingSocket);
This is the interesting exception trace
That is
Maybe that is due to some changes in the implementation in Java 17: the constructor reads the header (maybe that was not the case in Java 11?), and this generates an EOF since we indeed have an empty socket: