{"record":{"id":"10e8ab56a0ff0c87","repo":"apache/iceberg","slug":"namespace-already-exists-s-10e8ab","errorCode":null,"errorMessage":"Namespace already exists: %s","messagePattern":"Namespace already exists: (.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":409,"severity":"error","filePath":"nessie/src/main/java/org/apache/iceberg/nessie/NessieIcebergClient.java","lineNumber":228,"sourceCode":"    try {\n      ContentKey key = NessieUtil.toKey(tableIdentifier);\n      Content content = withReference(api.getContent().key(key)).get().get(key);\n      return content != null ? content.unwrap(IcebergContent.class).orElse(null) : null;\n    } catch (NessieNotFoundException e) {\n      return null;\n    }\n  }\n\n  public void createNamespace(Namespace namespace, Map<String, String> metadata) {\n    checkNamespaceIsValid(namespace);\n    getRef().checkMutable();\n    ContentKey key = ContentKey.of(namespace.levels());\n    org.projectnessie.model.Namespace content =\n        org.projectnessie.model.Namespace.of(key.getElements(), metadata);\n    try {\n      Content existing = api.getContent().reference(getReference()).key(key).get().get(key);\n      if (existing != null) {\n        throw namespaceAlreadyExists(key, existing, null);\n      }\n      try {\n        commitRetry(\"create namespace \" + key, Operation.Put.of(key, content));\n      } catch (NessieReferenceConflictException e) {\n        Optional<Conflict> conflict =\n            NessieUtil.extractSingleConflict(\n                e,\n                EnumSet.of(\n                    Conflict.ConflictType.KEY_EXISTS, Conflict.ConflictType.NAMESPACE_ABSENT));\n        if (conflict.isPresent()) {\n          switch (conflict.get().conflictType()) {\n            case KEY_EXISTS:\n              Content conflicting = withReference(api.getContent()).key(key).get().get(key);\n              throw namespaceAlreadyExists(key, conflicting, e);\n            case NAMESPACE_ABSENT:\n              throw new NoSuchNamespaceException(\n                  e,\n                  \"Cannot create namespace '%s': parent namespace '%s' does not exist\",","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/nessie/src/main/java/org/apache/iceberg/nessie/NessieIcebergClient.java#L210-L246","documentation":"NessieIcebergClient.createNamespace checks whether the ContentKey already exists in the configured reference before committing a Put operation. If the key resolves to existing content, it throws AlreadyExistsException 'Namespace already exists: <key>'. This mirrors the Iceberg REST contract for 409 on duplicate namespaces.","triggerScenarios":"Calling createNamespace(Namespace) on a Nessie catalog when an identically named namespace (ContentKey) already exists in the current reference, whether created earlier by you or by another writer.","commonSituations":"Re-running an idempotency-ignoring setup script; two jobs racing to create the same namespace; recreating a namespace after a branch reset where content still exists.","solutions":["Check existence first with namespaceExists(...) or catch AlreadyExistsException and treat it as success","Use a different namespace name or delete the existing namespace first","Verify you are pointed at the intended Nessie reference (branch/tag) via the catalog's ref configuration"],"exampleFix":"// before\ncatalog.createNamespace(Namespace.of(\"db\")); // AlreadyExistsException on rerun\n// after\nif (!catalog.namespaceExists(Namespace.of(\"db\"))) {\n  catalog.createNamespace(Namespace.of(\"db\"));\n}","handlingStrategy":"validation","validationCode":"if (catalog.namespaceExists(Namespace.of(\"db\"))) { /* skip or reuse */ } else { catalog.createNamespace(Namespace.of(\"db\")); }","typeGuard":null,"tryCatchPattern":"try { catalog.createNamespace(ns); } catch (AlreadyExistsException e) { /* treat as success */ }","preventionTips":["Make setup scripts idempotent with namespaceExists checks","Serialize namespace creation across jobs","Confirm the catalog's Nessie reference before setup"],"tags":["nessie","namespace","conflict","catalog"],"backgroundTag":"namespace-already-exists","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"}