You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2014/03/12 19:03:30 UTC
svn commit: r1576836 - in /qpid/jms/trunk/src:
main/java/org/apache/qpid/jms/impl/BytesMessageImpl.java
test/java/org/apache/qpid/jms/impl/BytesMessageImplTest.java
Author: robbie
Date: Wed Mar 12 18:03:30 2014
New Revision: 1576836
URL: http://svn.apache.org/r1576836
Log:
QPIDJMS-15: ensure we always throw the required IOOBE's, those raised as side effects of the method natural implementation dont account for some corner cases
Modified:
qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/BytesMessageImpl.java
qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/BytesMessageImplTest.java
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/BytesMessageImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/BytesMessageImpl.java?rev=1576836&r1=1576835&r2=1576836&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/BytesMessageImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/BytesMessageImpl.java Wed Mar 12 18:03:30 2014
@@ -308,7 +308,12 @@ public class BytesMessageImpl extends Me
public int readBytes(byte[] value, int length) throws JMSException
{
checkBodyReadable();
- //TODO: checking length, and bounds on the array
+
+ if(length < 0 || value.length < length)
+ {
+ throw new IndexOutOfBoundsException("length must not be negative or larger than the size of the provided array");
+ }
+
try
{
int offset = 0;
Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/BytesMessageImplTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/BytesMessageImplTest.java?rev=1576836&r1=1576835&r2=1576836&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/BytesMessageImplTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/BytesMessageImplTest.java Wed Mar 12 18:03:30 2014
@@ -428,6 +428,62 @@ public class BytesMessageImplTest extend
}
/**
+ * Verify that nothing is read when {@link BytesMessage#readBytes(byte[])} is
+ * called with a zero length destination array.
+ */
+ @Test
+ public void testReadBytesWithZeroLengthDestination() throws Exception
+ {
+ BytesMessageImpl bytesMessageImpl = new BytesMessageImpl(_mockSessionImpl,_mockConnectionImpl);
+ bytesMessageImpl.reset();
+
+ assertEquals("Did not expect any bytes to be read", 0, bytesMessageImpl.readBytes(new byte[0]));
+ }
+
+ /**
+ * Verify that when {@link BytesMessage#readBytes(byte[], int))} is called
+ * with a negative length that an {@link IndexOutOfBoundsException} is thrown.
+ */
+ @Test
+ public void testReadBytesWithNegativeLengthThrowsIOOBE() throws Exception
+ {
+ BytesMessageImpl bytesMessageImpl = new BytesMessageImpl(_mockSessionImpl,_mockConnectionImpl);
+ bytesMessageImpl.reset();
+
+ try
+ {
+ bytesMessageImpl.readBytes(new byte[0], -1);
+ fail("expected exception to be thrown");
+ }
+ catch(IndexOutOfBoundsException ioobe)
+ {
+ //expected
+ }
+ }
+
+ /**
+ * Verify that when {@link BytesMessage#readBytes(byte[], int))} is called
+ * with a length that is greater than the size of the provided array,
+ * an {@link IndexOutOfBoundsException} is thrown.
+ */
+ @Test
+ public void testReadBytesWithLengthGreatThanArraySizeThrowsIOOBE() throws Exception
+ {
+ BytesMessageImpl bytesMessageImpl = new BytesMessageImpl(_mockSessionImpl,_mockConnectionImpl);
+ bytesMessageImpl.reset();
+
+ try
+ {
+ bytesMessageImpl.readBytes(new byte[1], 2);
+ fail("expected exception to be thrown");
+ }
+ catch(IndexOutOfBoundsException ioobe)
+ {
+ //expected
+ }
+ }
+
+ /**
* Test that writing a short using {@link BytesMessage#writeShort(Object)}, resetting the
* message to make it readable, and then reading back the value using
* {@link BytesMessage#readUnsignedShort()} instead produces the expected the comes
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org