{"record":{"id":"cafd48be7a28f926","repo":"apache/iceberg","slug":"namespace-s-is-not-empty-contains-d-child-names-cafd48","errorCode":null,"errorMessage":"Namespace %s is not empty. Contains %d child namespace(s).","messagePattern":"Namespace (.+?) is not empty\\. Contains (.+?) child namespace\\(s\\)\\.","errorType":"exception","errorClass":"NamespaceNotEmptyException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java","lineNumber":548,"sourceCode":"  }\n\n  private String defaultNamespaceLocation(Namespace namespace) {\n    if (namespace.isEmpty()) {\n      return warehouseLocation;\n    } else {\n      return SLASH.join(warehouseLocation, SLASH.join(namespace.levels()));\n    }\n  }\n\n  @Override\n  public boolean dropNamespace(Namespace namespace) throws NamespaceNotEmptyException {\n    if (!namespaceExists(namespace)) {\n      return false;\n    }\n\n    List<Namespace> childNamespaces = listNamespaces(namespace);\n    if (childNamespaces != null && !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 != null && !tableIdentifiers.isEmpty()) {\n      throw new NamespaceNotEmptyException(\n          \"Namespace %s is not empty. Contains %d table(s).\", namespace, tableIdentifiers.size());\n    }\n\n    if (schemaVersion != JdbcUtil.SchemaVersion.V0) {\n      List<TableIdentifier> viewIdentifiers = listViews(namespace);\n      if (viewIdentifiers != null && !viewIdentifiers.isEmpty()) {\n        throw new NamespaceNotEmptyException(\n            \"Namespace %s is not empty. Contains %d view(s).\", namespace, viewIdentifiers.size());\n      }\n    }\n","sourceCodeStart":530,"sourceCodeEnd":566,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java#L530-L566","documentation":"dropNamespace throws NamespaceNotEmptyException when the namespace still contains child namespaces. The JDBC catalog only allows dropping empty namespaces to prevent accidental loss of namespaced tables. The count of child namespaces is included in the message.","triggerScenarios":"Calling catalog.dropNamespace(ns) while listNamespaces(ns) returns one or more child namespaces.","commonSituations":"Tearing down environments top-down without dropping leaf namespaces first; recursive namespace hierarchies created accidentally; cleanup scripts assuming a flat namespace layout.","solutions":["Drop all child namespaces first (recursively, bottom-up), then drop the parent","Drop or migrate all tables and views under the namespace before retrying","Catch NamespaceNotEmptyException in cleanup code and enumerate/drop contents programmatically"],"exampleFix":"// before\ncatalog.dropNamespace(ns);\n// after\nfor (Namespace child : catalog.listNamespaces(ns)) {\n  catalog.dropNamespace(child);\n}\ncatalog.dropNamespace(ns);","handlingStrategy":"validation","validationCode":"if (!catalog.listNamespaces(ns).isEmpty()) { throw new IllegalStateException(\"namespace has children\"); }","typeGuard":"boolean dropSafe = catalog.listNamespaces(ns).isEmpty() && catalog.listTables(ns).isEmpty();","tryCatchPattern":"try { catalog.dropNamespace(ns); } catch (NamespaceNotEmptyException e) { /* recursively drop children then retry */ }","preventionTips":["Drop namespaces bottom-up (children first)","Write recursive teardown helpers rather than assuming flat layouts","Purge tables and views before namespace cleanup in environment teardown scripts"],"tags":["jdbc-catalog","namespace-not-empty","namespace"],"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-23T08:17:48.524Z"}