{"record":{"id":"e7e60f83590d6932","repo":"apache/iceberg","slug":"namespace-s-is-not-empty-contains-d-view-s","errorCode":null,"errorMessage":"Namespace %s is not empty. Contains %d view(s).","messagePattern":"Namespace (.+?) is not empty\\. Contains (.+?) view\\(s\\)\\.","errorType":"exception","errorClass":"NamespaceNotEmptyException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java","lineNumber":238,"sourceCode":"        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)) {\n        throw new NoSuchNamespaceException(\"Namespace does not exist: %s\", namespace);\n      }\n\n      namespaces.computeIfPresent(\n          namespace,\n          (k, v) ->","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java#L220-L256","documentation":"NamespaceNotEmptyException from InMemoryCatalog.dropNamespace: the namespace contains one or more views (checked after child namespaces and tables), so removal is refused. The message reports the namespace and view count; drop the views before dropping the namespace.","triggerScenarios":"Calling catalog.dropNamespace(ns) when listViews(ns) returns non-empty results (tables were already dropped but views remain).","commonSituations":"View-only namespaces left behind after tables were removed; forgetting views exist in the namespace during teardown scripts.","solutions":["Drop all views via listViews then dropView before calling dropNamespace","Re-run dropNamespace after the views are removed","Check both tables and views defensively in teardown code"],"exampleFix":"// before\ncatalog.dropNamespace(ns);\n// after\ncatalog.listViews(ns).forEach(v -> catalog.dropView(v));\ncatalog.dropNamespace(ns);","handlingStrategy":"validation","validationCode":"if (!catalog.listViews(ns).isEmpty()) throw new IllegalStateException(\"Namespace has views: \" + ns);","typeGuard":null,"tryCatchPattern":"try { catalog.dropNamespace(ns); } catch (NamespaceNotEmptyException e) { /* drop views/tables first */ }","preventionTips":["Enumerate both listTables and listViews in teardown code","Treat views as first-class when cleaning namespaces"],"tags":["catalog","namespace","view","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"}