0 Replies Latest reply on Feb 21, 2007 9:40 AM by mkobold

    IOException: Incorrect number of bytes read.

    mkobold

      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");
       }
       }