qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject qpid-proton-j git commit: PROTON-1906: avoid potential NPE when duplicating composite buffer
Date Thu, 02 Aug 2018 16:12:23 GMT
Repository: qpid-proton-j
Updated Branches:
  refs/heads/0.27.x 5ba02a961 -> 3db1d9c5a


PROTON-1906: avoid potential NPE when duplicating composite buffer

(cherry picked from commit 6b7750775bf57d05f9a8f29d79e7fc3e38a8d0a1)


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/commit/3db1d9c5
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/tree/3db1d9c5
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/diff/3db1d9c5

Branch: refs/heads/0.27.x
Commit: 3db1d9c5a0a559e4b4badac91f00546253bc5c27
Parents: 5ba02a9
Author: Robbie Gemmell <robbie@apache.org>
Authored: Thu Aug 2 17:08:15 2018 +0100
Committer: Robbie Gemmell <robbie@apache.org>
Committed: Thu Aug 2 17:11:55 2018 +0100

----------------------------------------------------------------------
 .../proton/codec/CompositeReadableBuffer.java   |  4 +++-
 .../codec/CompositeReadableBufferTest.java      | 21 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/3db1d9c5/proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeReadableBuffer.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeReadableBuffer.java
b/proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeReadableBuffer.java
index 3780668..2c05e5f 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeReadableBuffer.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeReadableBuffer.java
@@ -66,7 +66,9 @@ public class CompositeReadableBuffer implements ReadableBuffer {
     private CompositeReadableBuffer(byte[] array, int offset) {
         this.currentArray = array;
         this.currentOffset = offset;
-        this.capacity = array.length;
+        if(array != null) {
+            this.capacity = array.length;
+        }
         this.limit = capacity;
     }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/3db1d9c5/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java
b/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java
index 4daef3e..2c41e7f 100644
--- a/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java
+++ b/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java
@@ -1763,6 +1763,27 @@ public class CompositeReadableBufferTest {
     //----- Test various cases of Duplicate ----------------------------------//
 
     @Test
+    public void testDuplicateOnEmptyBuffer() {
+        CompositeReadableBuffer buffer = new CompositeReadableBuffer();
+        CompositeReadableBuffer dup = buffer.duplicate();
+
+        assertNotSame(buffer, dup);
+        assertEquals(0, dup.capacity());
+        assertEquals(0, buffer.capacity());
+        assertEquals(0, dup.position());
+        assertEquals(0, buffer.position());
+        assertEquals(0, dup.limit());
+        assertEquals(0, buffer.limit());
+        assertContentEquals(buffer, dup);
+
+        try {
+            dup.reclaimRead();
+        } catch (Throwable t) {
+            fail("Compacting an empty duplicate should not fail");
+        }
+    }
+
+    @Test
     public void testDuplicateWithSingleArrayContent() {
         CompositeReadableBuffer buffer = new CompositeReadableBuffer();
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message