Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#8507] Add null check for namespace in ListTopicFailureEvent (#9854)

Sabah shaikh8e7b68cadea9
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());
+ });
+ }
+}