{"record":{"id":"79ee7b1cd9ad407a","repo":"apache/iceberg","slug":"cannot-create-namespace-s-namespace-already-exis","errorCode":null,"errorMessage":"Cannot create namespace %s. Namespace already exists","messagePattern":"Cannot create namespace (.+?)\\. Namespace already exists","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java","lineNumber":203,"sourceCode":"      if (views.containsKey(to)) {\n        throw new AlreadyExistsException(\"Cannot rename %s to %s. View already exists\", from, to);\n      }\n\n      tables.put(to, fromLocation);\n      tables.remove(from);\n    }\n  }\n\n  @Override\n  public void createNamespace(Namespace namespace) {\n    createNamespace(namespace, Collections.emptyMap());\n  }\n\n  @Override\n  public void createNamespace(Namespace namespace, Map<String, String> metadata) {\n    synchronized (this) {\n      if (namespaceExists(namespace)) {\n        throw new AlreadyExistsException(\n            \"Cannot create namespace %s. Namespace already exists\", namespace);\n      }\n\n      namespaces.put(namespace, ImmutableMap.copyOf(metadata));\n    }\n  }\n\n  @Override\n  public boolean namespaceExists(Namespace namespace) {\n    return namespaces.containsKey(namespace);\n  }\n\n  @Override\n  public boolean dropNamespace(Namespace namespace) throws NamespaceNotEmptyException {\n    synchronized (this) {\n      if (!namespaceExists(namespace)) {\n        return false;\n      }","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java#L185-L221","documentation":"InMemoryCatalog.createNamespace throws AlreadyExistsException when the namespace is already registered. The in-memory catalog stores namespaces in a map keyed by Namespace; duplicate creation is rejected rather than overwritten.","triggerScenarios":"Calling catalog.createNamespace(ns) or createNamespace(ns, metadata) twice for the same namespace, including creating the root-level namespace that already exists. The nested createNamespace overload delegates here, so both entry points can throw.","commonSituations":"Test setup run twice against a shared catalog instance; idempotent bootstrap scripts that assume create-if-not-exists semantics; parallel test classes initializing the same namespace.","solutions":["Check namespaceExists(namespace) before calling createNamespace","Wrap in try-catch for AlreadyExistsException for idempotent setup","Use a unique namespace name per test/run","Clear or recreate the catalog between runs"],"exampleFix":"// before\ncatalog.createNamespace(Namespace.of(\"test_ns\"));\n// after\nNamespace ns = Namespace.of(\"test_ns\");\nif (!catalog.namespaceExists(ns)) {\n  catalog.createNamespace(ns);\n}","handlingStrategy":"validation","validationCode":"Namespace ns = Namespace.of(\"test_ns\");\nif (!catalog.namespaceExists(ns)) { catalog.createNamespace(ns, metadata); }","typeGuard":null,"tryCatchPattern":"try { catalog.createNamespace(ns, metadata); } catch (AlreadyExistsException e) { /* idempotent: ignore */ }","preventionTips":["Guard creation with namespaceExists","Write idempotent setup helpers used by all tests","Isolate catalog instances per test run","Avoid assuming create-if-not-exists semantics"],"tags":["inmemory-catalog","namespace","already-exists"],"backgroundTag":"file-already-exists","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}