This is an automated email from the ASF dual-hosted git repository.
clebertsuconic pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/main by this push:
new 289587f004 ARTEMIS-3990 Ensure that readable buffer string read
consumes the bytes
289587f004 is described below
commit 289587f004ac46f7c175c9daa1585695cf9df917
Author: Timothy Bish <[email protected]>
AuthorDate: Tue Sep 13 16:21:34 2022 -0400
ARTEMIS-3990 Ensure that readable buffer string read consumes the bytes
Ensures that when reading a string the readable buffer consumes the
bytes by advancing the read index as defined in the interface API docs.
---
.../org/apache/activemq/artemis/protocol/amqp/util/NettyReadable.java | 4 ++--
.../apache/activemq/artemis/protocol/amqp/util/NettyReadableTest.java | 4 ++++
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/NettyReadable.java
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/NettyReadable.java
index b0679b5a68..6b14575f07 100644
---
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/NettyReadable.java
+++
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/NettyReadable.java
@@ -145,7 +145,7 @@ public class NettyReadable implements ReadableBuffer {
@Override
public String readUTF8() {
- return buffer.toString(Charset_UTF8);
+ return buffer.readCharSequence(buffer.readableBytes(),
Charset_UTF8).toString();
}
@Override
@@ -192,7 +192,7 @@ public class NettyReadable implements ReadableBuffer {
@Override
public String readString(CharsetDecoder decoder) throws
CharacterCodingException {
- return buffer.toString(decoder.charset());
+ return buffer.readCharSequence(buffer.readableBytes(),
decoder.charset()).toString();
}
@Override
diff --git
a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/util/NettyReadableTest.java
b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/util/NettyReadableTest.java
index 437d57b549..c3d473b288 100644
---
a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/util/NettyReadableTest.java
+++
b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/util/NettyReadableTest.java
@@ -438,7 +438,9 @@ public class NettyReadableTest {
NettyReadable buffer = new NettyReadable(byteBuffer);
+ assertEquals(asUtf8bytes.length, buffer.remaining());
assertEquals(testString, buffer.readUTF8());
+ assertEquals(0, buffer.remaining());
}
@Test
@@ -449,6 +451,8 @@ public class NettyReadableTest {
NettyReadable buffer = new NettyReadable(byteBuffer);
+ assertEquals(asUtf8bytes.length, buffer.remaining());
assertEquals(testString,
buffer.readString(StandardCharsets.UTF_8.newDecoder()));
+ assertEquals(0, buffer.remaining());
}
}