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 2018/08/02 16:10:34 UTC
qpid-proton-j git commit: PROTON-1906: avoid potential NPE when
duplicating composite buffer
Repository: qpid-proton-j
Updated Branches:
refs/heads/master 145b849c6 -> 6b7750775
PROTON-1906: avoid potential NPE when duplicating composite buffer
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/6b775077
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/tree/6b775077
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/diff/6b775077
Branch: refs/heads/master
Commit: 6b7750775bf57d05f9a8f29d79e7fc3e38a8d0a1
Parents: 145b849
Author: Robbie Gemmell <ro...@apache.org>
Authored: Thu Aug 2 17:08:15 2018 +0100
Committer: Robbie Gemmell <ro...@apache.org>
Committed: Thu Aug 2 17:08:15 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/6b775077/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 01654aa..c614e39 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/6b775077/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 85e0517..86ee4ab 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
@@ -2786,6 +2786,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