Skip to content

Commit

Permalink
[fix][common] TopicName: Throw IllegalArgumentException if localName …
Browse files Browse the repository at this point in the history
…is whitespace only (#23691)

(cherry picked from commit 034791f)
  • Loading branch information
pdolif authored and lhotari committed Dec 17, 2024
1 parent f9fcc13 commit 55630f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down

0 comments on commit 55630f9

Please sign in to comment.