Results 1 to 2 of 2
  1. #1
    yhqian99 is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default java.lang.IllegalStateException: unread block data when readObject

    Hi all,

    I am developing a Client/Server java application, where CSMessage is sent through socket.
    CSMessage has some data like String type and HashMap<String, String> type.

    the Client send message:

    private ObjectInputStream in;
    private ObjectOutputStream out;

    out = new ObjectOutputStream(socket.getOutputStream());
    in = new ObjectInputStream(socket.getInputStream());

    try
    {
    out.writeObject(message);
    out.flush();

    } catch (IOException e)
    {
    //...
    }


    and the following is the code snippet of the Server side:


    in = new ObjectInputStream(socket.getInputStream());
    out = new ObjectOutputStream(socket.getOutputStream());

    CSMessage fromClient = null;

    try
    {
    fromClient = (CSMessage) in.readObject();

    } catch (ClassNotFoundException e)
    {
    //.....
    }
    catch (IOException e)
    {
    //.... }
    }

    this code works fine for more than a year untill recently exception occurred intermittently:

    Exception in thread "Thread-72" java.lang.IllegalStateException: unread block data
    at java.io.ObjectInputStream$BlockDataInputStream.set BlockDataMode(ObjectInputStream.java:2393)
    at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1378)
    at java.io.ObjectInputStream.defaultReadFields(Object InputStream.java:1963)
    at java.io.ObjectInputStream.readSerialData(ObjectInp utStream.java:1887)
    at java.io.ObjectInputStream.readOrdinaryObject(Objec tInputStream.java:1770)
    at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1346)
    at java.io.ObjectInputStream.readObject(ObjectInputSt ream.java:368)
    at com.ictbox.acc.toolbarserver.AgentbarServerRequest Handler.handleRequest(AgentbarServerRequestHandler .java:1430)
    at com.ictbox.acc.toolbarserver.RequestThread.run(Req uestThread.java:189)

    sometimes we got another alternative exception :

    Exception in thread "Thread-58" java.lang.ClassCastException: cannot assign instance of com.ictbox.acc.utils.msg.CSMessage to field com.ictbox.acc.utils.msg.CSMessage.command of type java.lang.String in instance of com.ictbox.acc.utils.msg.CSMessage
    at java.io.ObjectStreamClass$FieldReflector.setObjFie ldValues(ObjectStreamClass.java:2056)
    at java.io.ObjectStreamClass.setObjFieldValues(Object StreamClass.java:1229)
    at java.io.ObjectInputStream.defaultReadFields(Object InputStream.java:1969)
    at java.io.ObjectInputStream.readSerialData(ObjectInp utStream.java:1887)
    at java.io.ObjectInputStream.readOrdinaryObject(Objec tInputStream.java:1770)
    at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1346)
    at java.io.ObjectInputStream.readObject(ObjectInputSt ream.java:368)
    at com.ictbox.acc.toolbarserver.AgentbarServerRequest Handler.handleRequest(AgentbarServerRequestHandler .java:1311)
    at com.ictbox.acc.toolbarserver.RequestThread.run(Req uestThread.java:189)

    or

    Exception in thread "Thread-26" java.lang.ClassCastException: java.lang.String cannot be cast to java.io.ObjectStreamClass
    at java.io.ObjectInputStream.readClassDesc(ObjectInpu tStream.java:1507)
    at java.io.ObjectInputStream.readOrdinaryObject(Objec tInputStream.java:1749)
    at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1346)
    at java.io.ObjectInputStream.defaultReadFields(Object InputStream.java:1963)
    at java.io.ObjectInputStream.readSerialData(ObjectInp utStream.java:1887)
    at java.io.ObjectInputStream.readOrdinaryObject(Objec tInputStream.java:1770)
    at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1346)
    at java.io.ObjectInputStream.readObject(ObjectInputSt ream.java:368)
    at com.ictbox.acc.toolbarserver.AgentbarServerRequest Handler.handleRequest(AgentbarServerRequestHandler .java:1326)
    at com.ictbox.acc.toolbarserver.RequestThread.run(Req uestThread.java:189)

    When this happen, the only way to make the system to work is to kill the process and restart it, that's bad!

    How to solve it? Any ideas are highly apprieciated.

    yhqian99

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,520
    Blog Entries
    7
    Rep Power
    20

    Default Re: java.lang.IllegalStateException: unread block data when readObject

    Did some of the classes on the client/server side get recompiled and/or did their serialVersionUID change?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 1
    Last Post: 08-12-2013, 09:59 AM
  2. Replies: 7
    Last Post: 09-26-2012, 01:32 PM
  3. Replies: 12
    Last Post: 09-17-2010, 12:40 AM
  4. GUI with java.lang.IllegalStateException
    By eckt in forum AWT / Swing
    Replies: 4
    Last Post: 06-14-2010, 10:32 AM
  5. Replies: 13
    Last Post: 09-07-2009, 04:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •