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 dd24c9a971210..b2f96bfe6e259 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 @@ private TopicName(String completeTopicName) { 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 485bea3f1addb..27eb82d15af0d 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 void topic() { // 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"));