Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.IllegalStateException:unread block data when reading objects from ObjectInputStream  RSS feed

 
Yuhong Qian
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.setBlockDataMode(ObjectInputStream.java:2393)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1378)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1963)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1887)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1770)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)
at com.ictbox.acc.toolbarserver.AgentbarServerRequestHandler.handleRequest(AgentbarServerRequestHandler.java:1430)
at com.ictbox.acc.toolbarserver.RequestThread.run(RequestThread.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.setObjFieldValues(ObjectStreamClass.java:2056)
at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:1229)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1969)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1887)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1770)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)
at com.ictbox.acc.toolbarserver.AgentbarServerRequestHandler.handleRequest(AgentbarServerRequestHandler.java:1311)
at com.ictbox.acc.toolbarserver.RequestThread.run(RequestThread.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(ObjectInputStream.java:1507)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1749)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1963)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1887)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1770)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)
at com.ictbox.acc.toolbarserver.AgentbarServerRequestHandler.handleRequest(AgentbarServerRequestHandler.java:1326)
at com.ictbox.acc.toolbarserver.RequestThread.run(RequestThread.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

 
Luan Cestari
Ranch Hand
Posts: 172
C++ Redhat Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it define either private void writeObject(java.io.ObjectOutputStream out) throws IOException or private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException ? How did you defined the serialVersionUID? Did you changed the JVM vendor or version recently? Did you updated all the jars in both client and server side (use md5 to check)?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!