That’s what’s supposed to happen. Your code is wrong. Check the Javadoc. readObject()
only returns null
if you wrote a null
. It doesn’t say anything about returning a null at EOF. Looping until readObject()
returns null
will only stop if you ever wrote a null
via writeObject()
, and if you didn’t you will get an EOFException
.