Skip to content

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

[#8302] fix(cli): Fix potential NPE in ListTables (#8325)

_.mungdc4cad8b411a
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java
index 1f098efce7..463ff732b0 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java
@@ -25,6 +25,7 @@ import org.apache.gravitino.Namespace;
import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.rel.Column;
import org.apache.gravitino.rel.Table;
+import org.apache.gravitino.rel.TableCatalog;
/** List the names of all tables in a schema. */
public class ListTables extends TableCommand {
@@ -50,13 +51,20 @@ public class ListTables extends TableCommand {
NameIdentifier[] tables = null;
Namespace name = Namespace.of(schema);
+ TableCatalog catalog = tableCatalog();
+ if (catalog == null) {
+ // The error message is already printed in the tableCatalog() method.
+ // We just need to exit here.
+ return;
+ }
+
try {
- tables = tableCatalog().listTables(name);
+ tables = catalog.listTables(name);
} catch (Exception exp) {
exitWithError(exp.getMessage());
}
- if (tables.length == 0) {
+ if (tables == null || tables.length == 0) {
printInformation("No tables exist.");
return;
}