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

jshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/main by this push:
     new 8e7b68cade [#8507] Add null check for namespace in 
ListTopicFailureEvent (#9854)
8e7b68cade is described below

commit 8e7b68cadea91c8c8059cb3845855e1acf6d4db0
Author: Sabah shaikh <[email protected]>
AuthorDate: Thu Feb 5 15:00:49 2026 +0530

    [#8507] Add null check for namespace in ListTopicFailureEvent (#9854)
    
    ### What changes were proposed in this pull request?
    
    Added a precondition check to ensure the namespace parameter is not null
    in `ListTopicFailureEvent` constructor using
    `Preconditions.checkNotNull()`.
    
    ### Why are the changes needed?
    
    To prevent NullPointerException and fail fast with a clear error message
    when null namespace is passed to the constructor.
    
    Fix: #8507
    
    ### Does this PR introduce any user-facing change?
    
    No
    
    ### How was this patch tested?
    
    Added unit test `testNamespaceMustNotBeNull()` to verify the null check
    throws NullPointerException when the namespace is null.
    
    ---------
    
    Co-authored-by: sabashaikh4 <[email protected]>
---
 .../listener/api/event/ListTopicFailureEvent.java  |  8 ++++-
 .../api/event/ListTopicFailureEventTest.java       | 35 ++++++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/gravitino/listener/api/event/ListTopicFailureEvent.java
 
b/core/src/main/java/org/apache/gravitino/listener/api/event/ListTopicFailureEvent.java
index beb574c8b8..8e5d82a3cd 100644
--- 
a/core/src/main/java/org/apache/gravitino/listener/api/event/ListTopicFailureEvent.java
+++ 
b/core/src/main/java/org/apache/gravitino/listener/api/event/ListTopicFailureEvent.java
@@ -19,6 +19,7 @@
 
 package org.apache.gravitino.listener.api.event;
 
+import com.google.common.base.Preconditions;
 import org.apache.gravitino.NameIdentifier;
 import org.apache.gravitino.Namespace;
 import org.apache.gravitino.annotation.DeveloperApi;
@@ -39,10 +40,15 @@ public final class ListTopicFailureEvent extends 
TopicFailureEvent {
    * @param exception The exception encountered during the attempt to list 
topics.
    */
   public ListTopicFailureEvent(String user, Namespace namespace, Exception 
exception) {
-    super(user, NameIdentifier.of(namespace.levels()), exception);
+    super(user, toNameIdentifier(namespace), exception);
     this.namespace = namespace;
   }
 
+  private static NameIdentifier toNameIdentifier(Namespace namespace) {
+    Preconditions.checkArgument(namespace != null, "namespace must not be 
null");
+    return NameIdentifier.of(namespace.levels());
+  }
+
   /**
    * Retrieves the namespace associated with this failure event.
    *
diff --git 
a/core/src/test/java/org/apache/gravitino/listener/api/event/ListTopicFailureEventTest.java
 
b/core/src/test/java/org/apache/gravitino/listener/api/event/ListTopicFailureEventTest.java
new file mode 100644
index 0000000000..7fa1df14e2
--- /dev/null
+++ 
b/core/src/test/java/org/apache/gravitino/listener/api/event/ListTopicFailureEventTest.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class ListTopicFailureEventTest {
+
+  @Test
+  public void testNamespaceMustNotBeNull() {
+    Assertions.assertThrows(
+        IllegalArgumentException.class,
+        () -> {
+          new ListTopicFailureEvent("user", null, new Exception());
+        });
+  }
+}

Reply via email to