Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

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

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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
    Last edited by yhqian99; May 1st, 2014 at 09:18 PM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,728
    My Mood
    Mellow
    Thanks
    172
    Thanked 622 Times in 609 Posts

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

    Hi, I don't think we've met, so welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly per the above link.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,094
    Thanks
    48
    Thanked 2,152 Times in 2,125 Posts

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

    works fine for more than a year untill recently
    What changed?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Jan 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    the change is the number of clients, which increases to about fourty to fifty.

    --- Update ---

    Quote Originally Posted by Norm View Post
    What changed?
    the change is the number of clients, which increases to about fourty to fifty.

Similar Threads

  1. Problems with readObject();
    By iHank in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 14th, 2014, 05:36 AM
  2. Replies: 2
    Last Post: July 2nd, 2013, 04:59 PM
  3. EOF Exception using InputStream/ReadObject
    By ryumishima44 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: July 20th, 2012, 06:06 AM
  4. IllegalStateException getOutputStream
    By NDSPTuba in forum Java Servlet
    Replies: 1
    Last Post: January 15th, 2011, 02:19 PM
  5. Read and unread forums
    By Json in forum The Cafe
    Replies: 23
    Last Post: June 17th, 2010, 07:30 AM