This is an automated email from the ASF dual-hosted git repository.
technoboy pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.10 by this push:
new 9f096da99ed [fix][broker] Fix can't send ErrorCommand when message is
null value (#19899)
9f096da99ed is described below
commit 9f096da99ed302816de2280ff5db2a90d0c0fddf
Author: Cong Zhao <[email protected]>
AuthorDate: Fri Mar 24 15:05:02 2023 +0800
[fix][broker] Fix can't send ErrorCommand when message is null value
(#19899)
---
.../apache/pulsar/client/api/ClientErrorsTest.java | 29 +++++++++++++++++++---
.../apache/pulsar/common/protocol/Commands.java | 4 +--
2 files changed, 28 insertions(+), 5 deletions(-)
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ClientErrorsTest.java
b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ClientErrorsTest.java
index ec4d56e6fbc..9763b297f9f 100644
---
a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ClientErrorsTest.java
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ClientErrorsTest.java
@@ -22,16 +22,15 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
-
import io.netty.channel.ChannelHandlerContext;
-
+import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
-
import lombok.Cleanup;
+import org.apache.bookkeeper.common.util.JsonUtil;
import org.apache.pulsar.client.impl.ConsumerBase;
import org.apache.pulsar.client.impl.PartitionedProducerImpl;
import org.apache.pulsar.client.impl.ProducerBase;
@@ -831,4 +830,28 @@ public class ClientErrorsTest {
mockBrokerService.resetHandleConnect();
mockBrokerService.resetHandleSubscribe();
}
+
+ @Test
+ public void testCommandErrorMessageIsNull() throws Exception {
+ @Cleanup
+ PulsarClient client =
PulsarClient.builder().serviceUrl(mockBrokerService.getBrokerAddress()).build();
+
+ mockBrokerService.setHandleProducer((ctx, producer) -> {
+ try {
+ ctx.writeAndFlush(Commands.newError(producer.getRequestId(),
ServerError.AuthorizationError, null));
+ } catch (Exception e) {
+ fail("Send error command failed", e);
+ }
+ });
+
+ try {
+ client.newProducer().topic("persistent://prop/use/ns/t1").create();
+ fail();
+ } catch (Exception e) {
+ assertTrue(e instanceof
PulsarClientException.AuthorizationException);
+ Map<String, String> map = JsonUtil.fromJson(e.getMessage(),
Map.class);
+ assertEquals(map.get("errorMsg"), "");
+ }
+ mockBrokerService.resetHandleProducer();
+ }
}
diff --git
a/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/Commands.java
b/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/Commands.java
index 924af8ac6a7..dadaa56ae60 100644
---
a/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/Commands.java
+++
b/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/Commands.java
@@ -364,7 +364,7 @@ public class Commands {
cmd.setError()
.setRequestId(requestId)
.setError(serverError)
- .setMessage(message);
+ .setMessage(message != null ? message : "");
return cmd;
}
@@ -397,7 +397,7 @@ public class Commands {
.setProducerId(producerId)
.setSequenceId(sequenceId)
.setError(error)
- .setMessage(errorMsg);
+ .setMessage(errorMsg != null ? errorMsg : "");
return cmd;
}