Author: timfox
Date: 2009-12-09 15:53:57 -0500 (Wed, 09 Dec 2009)
New Revision: 8655
Modified:
trunk/src/main/org/hornetq/jms/client/HornetQStreamMessage.java
trunk/tests/src/org/hornetq/tests/integration/jms/client/MessageTest.java
Log:
https://jira.jboss.org/jira/browse/HORNETQ-242
Modified: trunk/src/main/org/hornetq/jms/client/HornetQStreamMessage.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/HornetQStreamMessage.java 2009-12-09 20:37:28
UTC (rev 8654)
+++ trunk/src/main/org/hornetq/jms/client/HornetQStreamMessage.java 2009-12-09 20:53:57
UTC (rev 8655)
@@ -373,35 +373,42 @@
public Object readObject() throws JMSException
{
checkRead();
- byte type = getBuffer().readByte();
- switch (type)
+ try
{
- case DataConstants.BOOLEAN:
- return getBuffer().readBoolean();
- case DataConstants.BYTE:
- return getBuffer().readByte();
- case DataConstants.SHORT:
- return getBuffer().readShort();
- case DataConstants.CHAR:
- return (char)getBuffer().readShort();
- case
DataConstants.INT:
- return getBuffer().readInt();
- case DataConstants.LONG:
- return getBuffer().readLong();
- case DataConstants.FLOAT:
- return Float.intBitsToFloat(getBuffer().readInt());
- case DataConstants.DOUBLE:
- return Double.longBitsToDouble(getBuffer().readLong());
- case DataConstants.STRING:
- return getBuffer().readNullableString();
- case DataConstants.BYTES:
- int len = getBuffer().readInt();
- byte[] bytes = new byte[len];
- getBuffer().readBytes(bytes);
- return bytes;
- default:
- throw new MessageFormatException("Invalid conversion");
+ byte type = getBuffer().readByte();
+ switch (type)
+ {
+ case DataConstants.BOOLEAN:
+ return getBuffer().readBoolean();
+ case DataConstants.BYTE:
+ return getBuffer().readByte();
+ case DataConstants.SHORT:
+ return getBuffer().readShort();
+ case DataConstants.CHAR:
+ return (char)getBuffer().readShort();
+ case
DataConstants.INT:
+ return getBuffer().readInt();
+ case DataConstants.LONG:
+ return getBuffer().readLong();
+ case DataConstants.FLOAT:
+ return Float.intBitsToFloat(getBuffer().readInt());
+ case DataConstants.DOUBLE:
+ return Double.longBitsToDouble(getBuffer().readLong());
+ case DataConstants.STRING:
+ return getBuffer().readNullableString();
+ case DataConstants.BYTES:
+ int len = getBuffer().readInt();
+ byte[] bytes = new byte[len];
+ getBuffer().readBytes(bytes);
+ return bytes;
+ default:
+ throw new MessageFormatException("Invalid conversion");
+ }
}
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new MessageEOFException("");
+ }
}
public void writeBoolean(final boolean value) throws JMSException
Modified: trunk/tests/src/org/hornetq/tests/integration/jms/client/MessageTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/jms/client/MessageTest.java 2009-12-09
20:37:28 UTC (rev 8654)
+++ trunk/tests/src/org/hornetq/tests/integration/jms/client/MessageTest.java 2009-12-09
20:53:57 UTC (rev 8655)
@@ -16,9 +16,11 @@
import javax.jms.Connection;
import javax.jms.Message;
import javax.jms.MessageConsumer;
+import javax.jms.MessageEOFException;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
+import javax.jms.StreamMessage;
import junit.framework.Assert;
@@ -55,6 +57,160 @@
// Public --------------------------------------------------------
+ //https://jira.jboss.org/jira/browse/HORNETQ-242
+ public void testStreamMessageReadsNull() throws Exception
+ {
+ Connection conn = cf.createConnection();
+
+ Queue queue = createQueue("testQueue");
+
+ try
+ {
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sess.createProducer(queue);
+
+ MessageConsumer cons = sess.createConsumer(queue);
+
+ conn.start();
+
+ StreamMessage msg = sess.createStreamMessage();
+
+ msg.writeInt(1);
+ msg.writeInt(2);
+ msg.writeInt(3);
+
+
+ StreamMessage received = (StreamMessage)sendAndConsumeMessage(msg, prod, cons);
+
+ Assert.assertNotNull(received);
+
+ assertEquals(1, received.readObject());
+ assertEquals(2, received.readObject());
+ assertEquals(3, received.readObject());
+
+ try
+ {
+ received.readObject();
+
+ fail("Should throw exception");
+ }
+ catch (MessageEOFException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ received.readBoolean();
+
+ fail("Should throw exception");
+ }
+ catch (MessageEOFException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ received.readByte();
+
+ fail("Should throw exception");
+ }
+ catch (MessageEOFException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ received.readChar();
+
+ fail("Should throw exception");
+ }
+ catch (MessageEOFException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ received.readDouble();
+
+ fail("Should throw exception");
+ }
+ catch (MessageEOFException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ received.readFloat();
+
+ fail("Should throw exception");
+ }
+ catch (MessageEOFException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ received.readInt();
+
+ fail("Should throw exception");
+ }
+ catch (MessageEOFException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ received.readLong();
+
+ fail("Should throw exception");
+ }
+ catch (MessageEOFException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ received.readShort();
+
+ fail("Should throw exception");
+ }
+ catch (MessageEOFException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ received.readString();
+
+ fail("Should throw exception");
+ }
+ catch (MessageEOFException e)
+ {
+ //Ok
+ }
+ }
+ finally
+ {
+ try
+ {
+ conn.close();
+ }
+ catch (Throwable igonred)
+ {
+ }
+ }
+ }
+
public void testNullProperties() throws Exception
{
Connection conn = cf.createConnection();