{"record":{"id":"2de9217317705332","repo":"apache/iceberg","slug":"namespace-s-is-not-empty-contains-d-table-s","errorCode":null,"errorMessage":"Namespace %s is not empty. Contains %d table(s).","messagePattern":"Namespace (.+?) is not empty\\. Contains (.+?) table\\(s\\)\\.","errorType":"exception","errorClass":"NamespaceNotEmptyException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java","lineNumber":232,"sourceCode":"  }\n\n  @Override\n  public boolean dropNamespace(Namespace namespace) throws NamespaceNotEmptyException {\n    synchronized (this) {\n      if (!namespaceExists(namespace)) {\n        return false;\n      }\n\n      List<Namespace> childNamespaces = listNamespaces(namespace);\n      if (!childNamespaces.isEmpty()) {\n        throw new NamespaceNotEmptyException(\n            \"Namespace %s is not empty. Contains %d child namespace(s).\",\n            namespace, childNamespaces.size());\n      }\n\n      List<TableIdentifier> tableIdentifiers = listTables(namespace);\n      if (!tableIdentifiers.isEmpty()) {\n        throw new NamespaceNotEmptyException(\n            \"Namespace %s is not empty. Contains %d table(s).\", namespace, tableIdentifiers.size());\n      }\n\n      List<TableIdentifier> viewIdentifiers = listViews(namespace);\n      if (!viewIdentifiers.isEmpty()) {\n        throw new NamespaceNotEmptyException(\n            \"Namespace %s is not empty. Contains %d view(s).\", namespace, viewIdentifiers.size());\n      }\n\n      return namespaces.remove(namespace) != null;\n    }\n  }\n\n  @Override\n  public boolean setProperties(Namespace namespace, Map<String, String> properties)\n      throws NoSuchNamespaceException {\n    synchronized (this) {\n      if (!namespaceExists(namespace)) {","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java#L214-L250","documentation":"NamespaceNotEmptyException from InMemoryCatalog.dropNamespace: after checking child namespaces, the namespace still contains one or more tables, so it cannot be removed. The formatted message reports the namespace and the table count; drop or move the tables first.","triggerScenarios":"Calling catalog.dropNamespace(ns) after listTables(ns) returns one or more TableIdentifier entries.","commonSituations":"Cleaning up test namespaces without dropping tables first; migration scripts assuming drop cascades; parallel writers created tables after an isEmpty check.","solutions":["Drop all tables in the namespace first (listTables then dropTable for each), then retry dropNamespace","Also drop any views if present, since the next check rejects views too","Wrap the drop in a loop/retry if concurrent writers may add tables"],"exampleFix":"// before\ncatalog.dropNamespace(ns);\n// after\ncatalog.listTables(ns).forEach(t -> catalog.dropTable(t, false));\ncatalog.listViews(ns).forEach(v -> catalog.dropView(v));\ncatalog.dropNamespace(ns);","handlingStrategy":"validation","validationCode":"if (!catalog.listTables(ns).isEmpty()) throw new IllegalStateException(\"Namespace has tables: \" + ns);","typeGuard":null,"tryCatchPattern":"try { catalog.dropNamespace(ns); } catch (NamespaceNotEmptyException e) { /* drop children first */ }","preventionTips":["Always drop tables and views before dropNamespace","Guard concurrent writers with locks or retries"],"tags":["catalog","namespace","precondition"],"backgroundTag":"invalid-state-transition","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}