[
https://issues.apache.org/jira/browse/ARTEMIS-4327?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17736243#comment-17736243
]
Justin Bertram edited comment on ARTEMIS-4327 at 6/22/23 6:17 PM:
------------------------------------------------------------------
bq. Based on the name, I assumed that it would return {{null}} if the buffer
was empty, and if it was not, it would return a {{String}}.
That's not exactly correct. The method {{readNullableString}} is the
counter-part to {{writeNullableString}}. The methods {{writeString}} and
{{writeNullableString}} encode the {{String}} differently. If you use
{{writeString}} to write data to the buffer then you must use {{readString}} to
read that data. Likewise, if you use {{writeNullableString}} to write data to
the buffer then you must use {{readNullableString}} to read that data. Keep in
mind that many values can be written to the buffer in sequence and the buffer
won't be considered empty until the end of the buffer is reached (or if there
really is _no_ data in the buffer). It's useful to have {{null}} values
anywhere you want in the buffer, not just when it's empty.
bq. So if I am reading this correctly, this seems to be saying that if the
buffer starts with the byte 00, it will return null, even if the buffer is not
empty. Am I reading this correctly?
That's correct.
was (Author: jbertram):
bq. Based on the name, I assumed that it would return {{null}} if the buffer
was empty, and if it was not, it would return a {{String}}.
That's not exactly correct. The method {{readNullableString}} is the
counter-part to {{writeNullableString}}. The methods {{writeString}} and
{{writeNullableString}} encode the {{String}} differently. If you use
{{writeString}} to write data to the buffer then you must use {{readString}} to
read that data. Likewise, if you use {{writeNullableString}} to write data to
the buffer then you must use {{readNullableString}} to read that data. Keep in
mind that many values can be written to the buffer in sequence and the buffer
won't be considered empty until the end of the buffer is reached (or if there
really is _no_ data in the buffer). It's useful to have {{null}} values
anywhere you want in the buffer, not just when it's empty.
> AMQBuffer.readNullableString() is returning null when the buffer is not empty
> ------------------------------------------------------------------------------
>
> Key: ARTEMIS-4327
> URL: https://issues.apache.org/jira/browse/ARTEMIS-4327
> Project: ActiveMQ Artemis
> Issue Type: Bug
> Affects Versions: 2.19.1
> Environment: Artemis client is
> org.apache.activemq:artemis-core-client:2.19.1, Java code is using the
> Artemis Core API.
> Artemis server appears to be 2.28.0, and is running in a Docker container.
> Reporter: Chelsea Salyards
> Priority: Major
>
> *The Issue*
> Either I do not understand the intended functionality of
> {{AMQBuffer.readNullableString()}}, or it is not functioning correctly. Based
> on the name, I assumed that it would return {{null}} if the buffer was empty,
> and if it was not, it would return a {{String}}.
> In my client code, I have the following:
> {code:java}
> ServerLocator locator = ActiveMQClient.createServerLocator(AMQ_BROKER_URL);
> ClientSessionFactory sessionFactory = locator.createSessionFactory();
> ClientSession session = sessionFactory.createSession();
> session.start();
> Client message = session.createMessage(true);
> message.getBodyBuffer().writeString("test string");
> logger.debug("Regular string: " + message.getDataBuffer().readString());
> logger.debug("Nullable string: " +
> message.getDataBuffer().readNullableString());
> ClientProducer producer = session.createProducer("test-queue");
> producer.send(message);{code}
> The first debug output, using {{readString()}} prints out the string "test
> string" like I expect. However, the second debug output prints {{null}}, but
> I expected it to print "test string".
> *Potential Cause*
> I took a look at the message in the queue via the Artemis web console, and I
> can see the bytes for the message body are as follows:
> {noformat}
> 00 00 00 0b 00 0b 74 65 73 74 20 73 74 72 69 6e 67{noformat}
> Looking at the Artemis client source code, particularly the code for
> {{ChannelBufferWrapper}}, an implementation of the {{ActiveMQBuffer}} class,
> I see that {{readNullableString()}} is defined as the following:
> activemq-artemis/artemis-commons/src/main/java/org/apache/activemq/artemis/core/buffers/impl/ChannelBufferWrapper.java
> {code:java}
> public String readNullableString() {
> int b = buffer.readByte();
> if (b == DataConstants.NULL) {
> return null;
> }
> return readStringInternal();
> }{code}
> So if I am reading this correctly, this seems to be saying that if the buffer
> starts with the byte {{00}}, it will return {{null}}, even if the buffer is
> not empty. Am I reading this correctly? As shown in my example above, the
> message body starts with byte {{00}}.
> Other details about the message, if it helps:
> * durable: true
> * protocol: CORE
> * type: default
--
This message was sent by Atlassian Jira
(v8.20.10#820010)