13 Replies Latest reply: Dec 2, 2009 3:40 AM by 791266 RSS

    java.lang.IllegalStateException: unread block data

    843790
      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. Re: java.lang.IllegalStateException: unread block data
          843790
          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!!
          • 2. Re: java.lang.IllegalStateException: unread block data
            EJP
            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?
            • 3. Re: java.lang.IllegalStateException: unread block data
              843790
              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
              • 4. Re: java.lang.IllegalStateException: unread block data
                EJP
                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 ...
                • 5. Re: java.lang.IllegalStateException: unread block data
                  843790
                  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
                  • 6. Re: java.lang.IllegalStateException: unread block data
                    EJP
                    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 (-;
                    • 7. Re: java.lang.IllegalStateException: unread block data
                      843790
                      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.
                      • 8. Re: java.lang.IllegalStateException: unread block data
                        800288
                        I'm having the same trouble using Windows XP and JKD6
                        • 9. Re: java.lang.IllegalStateException: unread block data
                          800288
                          Found it!
                          In my case, the problem was the WindowsLookAndFeel.. :(
                          Awesome, but true.. Its solved (my case).. :)
                          • 10. Re: java.lang.IllegalStateException: unread block data
                            843790
                            Can you further explain what do you mean by the above statement?

                            I'm having the same problems and i'm on Window Xp. Kindly elaborate.

                            Thank You
                            (Problem still not solved)
                            • 11. Re: java.lang.IllegalStateException: unread block data
                              EJP
                              It has following declarations:
                              You can remove them, as they don't do anything that wouldn't happen if they weren't there. They just implement the default behaviour. I would remove it and retest.
                              Sometimes when reading the object we receive an exception java.lang.IllegalStateException: unread block data.
                              That indicates an internal error. Your code shouldn't cause it to be thrown.
                              It occurs more frequently if the file being read is on a NFS mounted partition.
                              Hmm ... this is a notorious source of problems. I would never use an NFS-mounted file in an application myself.
                              • 12. Re: java.lang.IllegalStateException: unread block data
                                843790
                                ejp wrote:
                                ...
                                Stuck in a loop there ejp?
                                • 13. Re: java.lang.IllegalStateException: unread block data
                                  791266
                                  dsouza_jude wrote:
                                  Can you further explain what do you mean by the above statement?

                                  I'm having the same problems and i'm on Window Xp. Kindly elaborate.

                                  Thank You
                                  (Problem still not solved)
                                  Create a new thread if you have a specific problem. Give a short but complete description of your environment and what you are trying to do. Don't hijack threads, and don't resurrect old threads. I'm locking this thread.

                                  Kaj