This is an automated email from the ASF dual-hosted git repository. tabish pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git
The following commit(s) were added to refs/heads/main by this push: new 6c463c2 PROTON-2410 Fix capture of read offset in other buffer in comparison 6c463c2 is described below commit 6c463c229c28f6d8b9d86e9af2e56be3169be716 Author: Timothy Bish <tabish...@gmail.com> AuthorDate: Thu Jul 15 16:06:39 2021 -0400 PROTON-2410 Fix capture of read offset in other buffer in comparison --- .../apache/qpid/protonj2/buffer/ProtonAbstractBuffer.java | 2 +- .../apache/qpid/protonj2/buffer/ProtonNettyByteBuffer.java | 2 +- .../qpid/protonj2/buffer/ProtonAbstractBufferTest.java | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/ProtonAbstractBuffer.java b/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/ProtonAbstractBuffer.java index c0ccb9a..beb2e7c 100644 --- a/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/ProtonAbstractBuffer.java +++ b/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/ProtonAbstractBuffer.java @@ -594,7 +594,7 @@ public abstract class ProtonAbstractBuffer implements ProtonBuffer { public int compareTo(ProtonBuffer other) { int length = getReadIndex() + Math.min(getReadableBytes(), other.getReadableBytes()); - for (int i = this.getReadIndex(), j = getReadIndex(); i < length; i++, j++) { + for (int i = getReadIndex(), j = other.getReadIndex(); i < length; i++, j++) { int cmp = Integer.compare(getByte(i) & 0xFF, other.getByte(j) & 0xFF); if (cmp != 0) { return cmp; diff --git a/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/ProtonNettyByteBuffer.java b/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/ProtonNettyByteBuffer.java index 8e13896..ff77b48 100644 --- a/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/ProtonNettyByteBuffer.java +++ b/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/ProtonNettyByteBuffer.java @@ -76,7 +76,7 @@ public final class ProtonNettyByteBuffer implements ProtonBuffer { public int compareTo(ProtonBuffer other) { int length = getReadIndex() + Math.min(getReadableBytes(), other.getReadableBytes()); - for (int i = this.getReadIndex(), j = getReadIndex(); i < length; i++, j++) { + for (int i = getReadIndex(), j = other.getReadIndex(); i < length; i++, j++) { int cmp = Integer.compare(getByte(i) & 0xFF, other.getByte(j) & 0xFF); if (cmp != 0) { return cmp; diff --git a/protonj2/src/test/java/org/apache/qpid/protonj2/buffer/ProtonAbstractBufferTest.java b/protonj2/src/test/java/org/apache/qpid/protonj2/buffer/ProtonAbstractBufferTest.java index 8842e2a..81d4e9a 100644 --- a/protonj2/src/test/java/org/apache/qpid/protonj2/buffer/ProtonAbstractBufferTest.java +++ b/protonj2/src/test/java/org/apache/qpid/protonj2/buffer/ProtonAbstractBufferTest.java @@ -1688,6 +1688,20 @@ public abstract class ProtonAbstractBufferTest { } @Test + public void testCompareToSameContentsButInOffsetBuffers() { + byte[] payload1 = new byte[] { 0, 1, 2, 3, 4 }; + byte[] payload2 = new byte[] { 9, 9, 9, 0, 1, 2, 3, 4 }; + ProtonBuffer buffer1 = wrapBuffer(payload1); + ProtonBuffer buffer2 = wrapBuffer(payload2); + + buffer2.setReadIndex(3); + + assertEquals(0, buffer1.compareTo(buffer1)); + assertEquals(0, buffer1.compareTo(buffer2)); + assertEquals(0, buffer2.compareTo(buffer1)); + } + + @Test public void testCompareToDifferentContents() { byte[] payload1 = new byte[] { 1, 2, 3, 4, 5 }; byte[] payload2 = new byte[] { 0, 1, 2, 3, 4 }; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org