[
https://issues.apache.org/jira/browse/ARTEMIS-4327?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Chelsea Salyards updated ARTEMIS-4327:
--------------------------------------
Description:
*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:
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);
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:
00 00 00 0b 00 0b 74 65 73 74 20 73 74 72 69 6e 67
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
public String readNullableString() {
int b = buffer.readByte();
if (b == DataConstants.NULL)
{ return null; }
return readStringInternal();
}
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
was:
*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:
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);
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:
00 00 00 0b 00 0b 74 65 73 74 20 73 74 72 69 6e 67
I took a look at the Artemis client source code, and looking at 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
public String readNullableString() {
int b = buffer.readByte();
if (b == DataConstants.NULL) {
return null;
}
return readStringInternal();
}
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
> 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
> Components: ActiveMQ-Artemis-Native
> 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
> Assignee: Clebert Suconic
> 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:
>
> 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);
>
> 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:
>
> 00 00 00 0b 00 0b 74 65 73 74 20 73 74 72 69 6e 67
>
> 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
> public String readNullableString() {
> int b = buffer.readByte();
> if (b == DataConstants.NULL)
> { return null; }
> return readStringInternal();
> }
>
> 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)