You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by te...@apache.org on 2024/12/17 06:23:21 UTC

(pulsar) branch master updated: [fix][common] TopicName: Throw IllegalArgumentException if localName is whitespace only (#23691)

This is an automated email from the ASF dual-hosted git repository.

technoboy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 034791f66b3 [fix][common] TopicName: Throw IllegalArgumentException if localName is whitespace only (#23691)
034791f66b3 is described below

commit 034791f66b3b91489ab2819f93c7f1fbcc3d8c38
Author: Philipp Dolif <52...@users.noreply.github.com>
AuthorDate: Tue Dec 17 07:23:13 2024 +0100

    [fix][common] TopicName: Throw IllegalArgumentException if localName is whitespace only (#23691)
---
 .../src/main/java/org/apache/pulsar/common/naming/TopicName.java   | 6 +++---
 .../test/java/org/apache/pulsar/common/naming/TopicNameTest.java   | 7 +++++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicName.java b/pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicName.java
index dd24c9a9712..b2f96bfe6e2 100644
--- a/pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicName.java
+++ b/pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicName.java
@@ -170,9 +170,9 @@ public class TopicName implements ServiceUnitId {
                 throw new IllegalArgumentException("Invalid topic name: " + completeTopicName);
             }
 
-
-            if (localName == null || localName.isEmpty()) {
-                throw new IllegalArgumentException("Invalid topic name: " + completeTopicName);
+            if (StringUtils.isBlank(localName)) {
+                throw new IllegalArgumentException(String.format("Invalid topic name: %s. Topic local name must not"
+                        + " be blank.", completeTopicName));
             }
 
         } catch (NullPointerException e) {
diff --git a/pulsar-common/src/test/java/org/apache/pulsar/common/naming/TopicNameTest.java b/pulsar-common/src/test/java/org/apache/pulsar/common/naming/TopicNameTest.java
index 485bea3f1ad..27eb82d15af 100644
--- a/pulsar-common/src/test/java/org/apache/pulsar/common/naming/TopicNameTest.java
+++ b/pulsar-common/src/test/java/org/apache/pulsar/common/naming/TopicNameTest.java
@@ -177,6 +177,13 @@ public class TopicNameTest {
             // Ok
         }
 
+        try {
+            TopicName.get(" ");
+            fail("Should have raised exception");
+        } catch (IllegalArgumentException e) {
+            // Ok
+        }
+
         TopicName nameWithSlash = TopicName.get("persistent://tenant/cluster/namespace/ns-abc/table/1");
         assertEquals(nameWithSlash.getEncodedLocalName(), Codec.encode("ns-abc/table/1"));