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

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


The following commit(s) were added to refs/heads/master by this push:
     new 37932bf60 RATIS-2610. -groupid should check for non-empty ID (#1523)
37932bf60 is described below

commit 37932bf60111bd1a26d047d9bd33c46faa5f7022
Author: Abhishek Pal <[email protected]>
AuthorDate: Tue Jul 21 01:25:36 2026 +0530

    RATIS-2610. -groupid should check for non-empty ID (#1523)
---
 .../java/org/apache/ratis/shell/cli/CliUtils.java  |  2 +-
 .../org/apache/ratis/shell/cli/TestCliUtils.java   | 25 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/CliUtils.java 
b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/CliUtils.java
index a4a30ae77..08999a722 100644
--- a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/CliUtils.java
+++ b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/CliUtils.java
@@ -96,7 +96,7 @@ public final class CliUtils {
 
   /** Parse the given string as a {@link RaftGroupId}. */
   public static RaftGroupId parseRaftGroupId(String groupId) {
-    return groupId != null && groupId.isEmpty() ? 
RaftGroupId.valueOf(UUID.fromString(groupId)) : null;
+    return groupId != null && !groupId.isEmpty() ? 
RaftGroupId.valueOf(UUID.fromString(groupId)) : null;
   }
 
   /**
diff --git 
a/ratis-test/src/test/java/org/apache/ratis/shell/cli/TestCliUtils.java 
b/ratis-test/src/test/java/org/apache/ratis/shell/cli/TestCliUtils.java
index 151914b64..2bdac3ab9 100644
--- a/ratis-test/src/test/java/org/apache/ratis/shell/cli/TestCliUtils.java
+++ b/ratis-test/src/test/java/org/apache/ratis/shell/cli/TestCliUtils.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ratis.shell.cli;
 
+import org.apache.ratis.protocol.RaftGroupId;
 import org.apache.ratis.protocol.RaftPeer;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
@@ -25,6 +26,7 @@ import java.net.Inet4Address;
 import java.net.Inet6Address;
 import java.net.InetSocketAddress;
 import java.util.List;
+import java.util.UUID;
 
 public class TestCliUtils {
 
@@ -61,4 +63,27 @@ public class TestCliUtils {
     Assertions.assertThrows(IllegalArgumentException.class,
         () -> CliUtils.parseInetSocketAddress("http://127.0.0.1:6000";));
   }
+
+  @Test
+  public void testParseRaftGroupIdNull() {
+    Assertions.assertNull(CliUtils.parseRaftGroupId(null));
+  }
+
+  @Test
+  public void testParseRaftGroupIdEmpty() {
+    Assertions.assertNull(CliUtils.parseRaftGroupId(""));
+  }
+
+  @Test
+  public void testParseRaftGroupIdValid() {
+    final UUID uuid = UUID.randomUUID();
+    final RaftGroupId groupId = CliUtils.parseRaftGroupId(uuid.toString());
+    Assertions.assertEquals(RaftGroupId.valueOf(uuid), groupId);
+  }
+
+  @Test
+  public void testParseRaftGroupIdInvalid() {
+    Assertions.assertThrows(IllegalArgumentException.class,
+        () -> CliUtils.parseRaftGroupId("not-a-uuid"));
+  }
 }

Reply via email to