[jboss-user] [Messaging, JMS & JBossMQ] - IOException: Incorrect number of bytes read.

mkobold do-not-reply at jboss.com
Wed Feb 21 09:40:57 EST 2007


Using JBoss 4.0.5-GA with JDK 1.5.0_06 and getting this issue with JBossMQ when the MDB is trying to acquire our business data object from the body of an ObjectMessage

  | javax.jms.MessageFormatException: IOException: Incorrect number of bytes read.
  |         at org.jboss.mq.SpyObjectMessage.getObject(SpyObjectMessage.java:158)
  | 

I did some groundwork looking for a solution and I can't seem to find any posting regarding this issue. I also included the method that i believe to be the culprit of this issue. On setObject(Serializable) the flush() method is not called prior to extracting byte array from ByteArrayOutputStream. So I would suspect that if the ObjectOutputStream did not by chance automatically flush to the memory stream it would make sense why some bytes appear to be lost.



  |  public void setObject(Serializable object) throws JMSException
  |    {
  |       if (header.msgReadOnly)
  |         {
  |          throw new MessageNotWriteableException("setObject");
  |       }
  |       if (object == null)
  |       {
  |          objectBytes = null;
  |          return;
  |       }
  |       try
  |       {
  |          if (object instanceof byte[])
  |            {
  |             //cheat for byte arrays
  |             isByteArray = true;
  |             objectBytes = new byte[((byte[]) object).length];
  |             System.arraycopy(object, 0, objectBytes, 0, objectBytes.length);
  |          }
  |          else
  |            {
  |             isByteArray = false;
  |             ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
  |             ObjectOutputStream objectOut = new ObjectOutputStream(byteArray);
  |             objectOut.writeObject(object);
  |             objectBytes = byteArray.toByteArray();
  |             objectOut.close();
  |          }
  |       }
  |       catch (IOException e)
  |       {
  |          throw new MessageFormatException("Object cannot be serialized");
  |       }
  |    }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4019958#4019958

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4019958



More information about the jboss-user mailing list