{"record":{"id":"cd376bd3ad87959d","repo":"pentaho/pentaho-kettle","slug":"namespace-with-name-namespace-already-exists","errorCode":null,"errorMessage":"Namespace with name ''+namespace+'' already exists","messagePattern":"Namespace with name ''\\+namespace\\+'' already exists","errorType":"exception","errorClass":"MetaStoreNamespaceExistsException","httpStatus":null,"severity":"warning","filePath":"engine/src/main/java/org/pentaho/di/repository/kdr/delegates/metastore/KettleDatabaseRepositoryMetaStore.java","lineNumber":79,"sourceCode":"      for ( RowMetaAndData namespaceRow : namespaceRows ) {\n        String namespace = namespaceRow.getString( KettleDatabaseRepository.FIELD_NAMESPACE_NAME, null );\n        if ( !Utils.isEmpty( namespace ) ) {\n          namespaces.add( namespace );\n        }\n      }\n      return namespaces;\n\n    } catch ( Exception e ) {\n      throw new MetaStoreException( e );\n    }\n  }\n\n  @Override\n  public void createNamespace( String namespace ) throws MetaStoreException, MetaStoreNamespaceExistsException {\n    try {\n      ObjectId namespaceId = delegate.getNamespaceId( namespace );\n      if ( namespaceId != null ) {\n        throw new MetaStoreNamespaceExistsException( \"Namespace with name '\" + namespace + \"' already exists\" );\n      }\n\n      // insert namespace into R_NAMESPACE\n      //\n      delegate.insertNamespace( namespace );\n      repository.commit();\n    } catch ( Exception e ) {\n      repository.rollback();\n      throw new MetaStoreException( e );\n    }\n  }\n\n  @Override\n  public void deleteNamespace( String namespace ) throws MetaStoreException, MetaStoreDependenciesExistsException {\n    try {\n      ObjectId namespaceId = delegate.verifyNamespace( namespace );\n\n      List<IMetaStoreElementType> elementTypes = getElementTypes( namespace );","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/kdr/delegates/metastore/KettleDatabaseRepositoryMetaStore.java#L61-L97","documentation":"createNamespace() first looks up the namespace by name; if a row already exists it throws MetaStoreNamespaceExistsException('Namespace with name X already exists'). This is a deliberate guard so namespaces remain unique in R_NAMESPACE.","triggerScenarios":"metastore.createNamespace(name) where delegate.getNamespaceId(name) returns a non-null id, i.e. the namespace name already exists in the repository.","commonSituations":"Initialization code that runs on every startup calling createNamespace unconditionally; two jobs racing to create the same namespace; re-running a setup script after partial execution.","solutions":["Call namespaceExists(name) first and skip creation if it returns true","Catch MetaStoreNamespaceExistsException and treat it as a no-op when idempotent setup is intended","Use a distinct namespace name if a genuinely new namespace is required"],"exampleFix":"// before\nmetaStore.createNamespace(\"pentaho\"); // throws on second run\n// after\nif (!metaStore.namespaceExists(\"pentaho\")) {\n  metaStore.createNamespace(\"pentaho\");\n}","handlingStrategy":"validation","validationCode":"if (!metaStore.namespaceExists(namespace)) {\n  metaStore.createNamespace(namespace);\n}","typeGuard":null,"tryCatchPattern":"try { metaStore.createNamespace(ns); } catch (MetaStoreNamespaceExistsException e) { /* idempotent: already exists, ignore */ }","preventionTips":["Make setup code idempotent: check existence before create","Serialize namespace creation in concurrent jobs to avoid races","Use try/catch on MetaStoreNamespaceExistsException for one-time initialization scripts"],"tags":["metastore","namespace","duplicate","conflict"],"backgroundTag":"file-already-exists","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}