apache/iceberg · error · NoSuchNamespaceException

Cannot list tables for namespace. Namespace does not exist:

Error message

Cannot list tables for namespace. Namespace does not exist: %s

What it means

InMemoryCatalog.listTables throws NoSuchNamespaceException when the requested namespace does not exist and is not empty (root). The in-memory catalog keeps namespaces explicitly; listing tables requires a valid namespace.

Source

Thrown at core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java:154

    }

    synchronized (this) {
      if (null == tables.remove(tableIdentifier)) {
        return false;
      }
    }

    if (purge && lastMetadata != null) {
      CatalogUtil.dropTableData(ops.io(), lastMetadata);
    }

    return true;
  }

  @Override
  public List<TableIdentifier> listTables(Namespace namespace) {
    if (!namespaceExists(namespace) && !namespace.isEmpty()) {
      throw new NoSuchNamespaceException(
          "Cannot list tables for namespace. Namespace does not exist: %s", namespace);
    }

    return tables.keySet().stream()
        .filter(t -> t.namespace().equals(namespace))
        .sorted(Comparator.comparing(TableIdentifier::toString))
        .collect(Collectors.toList());
  }

  @Override
  public void renameTable(TableIdentifier from, TableIdentifier to) {
    if (from.equals(to)) {
      return;
    }

    synchronized (this) {
      if (!namespaceExists(to.namespace())) {
        throw new NoSuchNamespaceException(

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Call namespaceExists(namespace) first and create it if missing
  2. Correct the namespace identifier spelling/casing
  3. List namespaces with listNamespaces() to see what exists
  4. Catch NoSuchNamespaceException and return an empty list if acceptable

Example fix

// before
List<TableIdentifier> tables = catalog.listTables(Namespace.of("reporting"));
// after
Namespace ns = Namespace.of("reporting");
if (catalog.namespaceExists(ns)) {
  List<TableIdentifier> tables = catalog.listTables(ns);
}
Defensive patterns

Strategy: validation

Validate before calling

Namespace ns = Namespace.of("reporting");
if (!catalog.namespaceExists(ns)) { catalog.createNamespace(ns); }

Try / catch

try { return catalog.listTables(ns); } catch (NoSuchNamespaceException e) { return List.of(); }

Prevention

When it happens

Trigger: Calling catalog.listTables(Namespace.of("a")) where namespace "a" was never created (or was dropped). Passing a multi-level namespace whose parent exists but leaf does not.

Common situations: Hardcoded namespace names that drift from what was created in tests; namespaces dropped by prior cleanup; case-sensitivity mismatches in namespace strings.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/6133bfdae8e188c3. Report an issue: GitHub.