java.lang.IllegalStateException: unread block data

Hi all,

We are using very simple serialization for a object in our application. It has following declarations:

private void writeObject(ObjectOutputStream aOutputStream)

throws IOException {

aOutputStream.defaultWriteObject();

}

private void readObject(ObjectInputStream aInputStream)

throws ClassNotFoundException, IOException {

aInputStream.defaultReadObject();

}

Sometimes when reading the object we receive an exception java.lang.IllegalStateException: unread block data. I have no idea why it occurs. It occurs more frequently if the file being read is on a NFS mounted partition. Here is the code we are using for reading:

FileInputStream fin = new FileInputStream(fileName);

ObjectInputStream ois = new ObjectInputStream(fin);

Object o = ois.readObject();

ois.close();

I have tried with both Java 1.5 and 1.6 (on Linux 32-bit). Any help will be greatly appreciated.

thanks

Nilesh

[995 byte] By [nileshbansala] at [2007-11-26 18:30:05]
# 1

A complete statck trace for above problem is:

[] java.lang.IllegalStateException: unread block data

at java.io.ObjectInputStream$BlockDataInputStream.setBlockDataMode(ObjectInputStream.java:2375)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1361)

at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1945)

at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:480)

at blogoscope.statistics.tfidf.DayTF.readObject(DayTF.java:271)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)

at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1846)

at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)

at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)

at blogoscope.base.utils.Serializer.readFromFile(Serializer.java:25)

at blogoscope.statistics.tfidf.DayTF.readFromFile(DayTF.java:91)

at blogoscope.statistics.tfidf.CheckDayTF.main(CheckDayTF.java:36)

The same code works fine most of the times, but sometimes it gives this wierd exception. I have no idea why it happens!!

nileshbansala at 2007-7-9 6:04:16 > top of Java-index,Core,Core APIs...
# 2
Those methods don't actually change the default serialization, at least they shouldn't, so it is possible to try serializing and deserializing with a version of the class where they are commented out?
ejpa at 2007-7-9 6:04:16 > top of Java-index,Core,Core APIs...
# 3
Thanks ejp for your reply. I have tried commenting the readObject and writeObject methods from the class definition. Reading the object still results in the same error.-Nilesh
nileshbansala at 2007-7-9 6:04:16 > top of Java-index,Core,Core APIs...
# 4
Hmm, bizarre. Does the class have:(a) a serialVersionUID?(b) writeReplace() and readResolve() methods?Also what streams are you using to write and read the serialization?Still fishing for an idea here ...
ejpa at 2007-7-9 6:04:16 > top of Java-index,Core,Core APIs...
# 5

It has

static final long serialVersionUID = 42L;

There are no readResolv and writeReplace methods in the class definition.

For writing an Object o, I am using:

FileOutputStream fout = new FileOutputStream(fileName);

ObjectOutputStream oos = new ObjectOutputStream(fout);

oos.writeObject(o);

oos.close();

And to read Object o:

FileInputStream fin = new FileInputStream(fileName);

ObjectInputStream ois = new ObjectInputStream(fin);

Object o = ois.readObject();

ois.close();

fin.close();

return o;

thanks

Nilesh

nileshbansala at 2007-7-9 6:04:16 > top of Java-index,Core,Core APIs...
# 6
Curiouser and curiouser. The NFS thing is a hint. Maybe you're getting a read error somewhere along the chain. If it was a Java bug it would happen every time. not intermittently. And we've reduced the problem to its simplest possible form. So I am baffled (-;
ejpa at 2007-7-9 6:04:16 > top of Java-index,Core,Core APIs...
# 7
The error occurs when not using NFS also. Just that the probability of error increases if the underlying filesystem is NFS mounted. And the error occurs sometimes, and sometimes it disappears. To me it seems to be a Java (or OS, i.e., Linux) bug.
nileshbansala at 2007-7-9 6:04:16 > top of Java-index,Core,Core APIs...