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