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
# 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!!
# 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