diff --git a/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQStreamMessage.java b/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQStreamMessage.java index 5501e53d36..8fe2358135 100755 --- a/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQStreamMessage.java +++ b/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQStreamMessage.java @@ -1089,7 +1089,9 @@ public class ActiveMQStreamMessage extends ActiveMQMessage implements StreamMess writeBytes((byte[])value); }else if (value instanceof Long) { writeLong(((Long)value).longValue()); - } + }else { + throw new MessageFormatException("Unsupported Object type: " + value.getClass()); + } } /** diff --git a/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQStreamMessageTest.java b/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQStreamMessageTest.java index d4f80b2e8b..ff2bf0beb0 100755 --- a/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQStreamMessageTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQStreamMessageTest.java @@ -754,14 +754,10 @@ public class ActiveMQStreamMessageTest extends TestCase { public void testClearBody() throws JMSException { ActiveMQStreamMessage streamMessage = new ActiveMQStreamMessage(); try { - streamMessage.writeObject(new Serializable() { - private static final long serialVersionUID = -5181896809607968727L; - }); + streamMessage.writeObject(new Long(2)); streamMessage.clearBody(); assertFalse(streamMessage.isReadOnlyBody()); - streamMessage.writeObject(new Serializable() { - private static final long serialVersionUID = 5074177640797561141L; - }); + streamMessage.writeObject(new Long(2)); streamMessage.readObject(); fail("should throw exception"); } catch (MessageNotReadableException mnwe) { @@ -972,5 +968,33 @@ public class ActiveMQStreamMessageTest extends TestCase { } catch (MessageNotReadableException e) { } } + + public void testWriteObject() { + try { + ActiveMQStreamMessage message = new ActiveMQStreamMessage(); + message.clearBody(); + message.writeObject("test"); + message.writeObject(new Character('a')); + message.writeObject(new Boolean(false)); + message.writeObject(new Byte((byte) 2)); + message.writeObject(new Short((short) 2)); + message.writeObject(new Integer(2)); + message.writeObject(new Long(2l)); + message.writeObject(new Float(2.0f)); + message.writeObject(new Double(2.0d)); + }catch(Exception e) { + fail(e.getMessage()); + } + try { + ActiveMQStreamMessage message = new ActiveMQStreamMessage(); + message.clearBody(); + message.writeObject(new Object()); + fail("should throw an exception"); + }catch(MessageFormatException e) { + + }catch(Exception e) { + fail(e.getMessage()); + } + } }