From 58b8d19a970c0cdba90fd6372739ae13b0891af6 Mon Sep 17 00:00:00 2001 From: Robert Davies Date: Wed, 22 Oct 2008 13:02:31 +0000 Subject: [PATCH] Fix for https://issues.apache.org/activemq/browse/AMQ-1964 git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@707064 13f79535-47bb-0310-9956-ffa450edef68 --- .../command/ActiveMQStreamMessage.java | 4 ++- .../command/ActiveMQStreamMessageTest.java | 36 +++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) 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()); + } + } }