{"record":{"id":"16f68c64efa863a9","repo":"apolloconfig/apollo","slug":"private-appnamespace-already-exists","errorCode":null,"errorMessage":"Private AppNamespace {} already exists!","messagePattern":"Private AppNamespace (.+?) already exists!","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java","lineNumber":175,"sourceCode":"    if (!ConfigFileFormat.isValidFormat(appNamespace.getFormat())) {\n      throw BadRequestException\n          .invalidNamespaceFormat(\"format must be properties、json、yaml、yml、xml\");\n    }\n\n    if (StringUtils.isEmpty(appNamespace.getDataChangeCreatedBy())) {\n      appNamespace.setDataChangeCreatedBy(operator);\n    }\n\n    appNamespace.setDataChangeLastModifiedBy(operator);\n\n    // globally uniqueness check for public app namespace\n    if (appNamespace.isPublic()) {\n      checkAppNamespaceGlobalUniqueness(appNamespace);\n    } else {\n      // check private app namespace\n      if (appNamespaceRepository.findByAppIdAndName(appNamespace.getAppId(),\n          appNamespace.getName()) != null) {\n        throw new BadRequestException(\n            \"Private AppNamespace \" + appNamespace.getName() + \" already exists!\");\n      }\n      // should not have the same with public app namespace\n      checkPublicAppNamespaceGlobalUniqueness(appNamespace);\n    }\n\n    AppNamespace createdAppNamespace = appNamespaceRepository.save(appNamespace);\n\n    roleInitializationService.initNamespaceRoles(appNamespace.getAppId(), appNamespace.getName(),\n        operator);\n    roleInitializationService.initNamespaceEnvRoles(appNamespace.getAppId(), appNamespace.getName(),\n        operator);\n\n    return createdAppNamespace;\n  }\n\n  @Transactional\n  public AppNamespace importAppNamespaceInLocal(AppNamespace appNamespace) {","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java#L157-L193","documentation":"Thrown during custom AppNamespace creation (the create() path) when a PRIVATE namespace with the same appId+name already exists in the repository (findByAppIdAndName != null). BadRequestException → HTTP 400. The {} is the namespace name substituted via string concatenation. After this check it also verifies the name does not collide with any PUBLIC namespace.","triggerScenarios":"Creating a private namespace whose appId+name pair already exists in the AppNamespace table; duplicate submission of the same namespace within one app.","commonSituations":"User clicks create twice; a previous successful creation was not reflected in the UI before retry; import tool re-runs over existing data.","solutions":["Check findByAppIdAndName(appId, name) == null before creating.","Refresh the namespace list in the UI to avoid stale duplicate submissions.","Choose a different namespace name if a duplicate is legitimately needed."],"exampleFix":"// before\nappNamespaceService.create(appNamespace);\n\n// after\nif (appNamespaceRepository.findByAppIdAndName(appNamespace.getAppId(), appNamespace.getName()) != null) {\n  return existing; // or skip\n}\nappNamespaceService.create(appNamespace);","handlingStrategy":"validation","validationCode":"if (appNamespaceRepository.findByAppIdAndName(ns.getAppId(), ns.getName()) != null) {\n  return ResponseEntity.badRequest().body(\"namespace already exists\");\n}","typeGuard":"boolean isUniquePrivateNamespace(String appId, String name, AppNamespaceRepository repo) {\n  return repo.findByAppIdAndName(appId, name) == null;\n}","tryCatchPattern":null,"preventionTips":["Check appId+name uniqueness before creating a private namespace.","De-duplicate UI submissions to avoid double-creates."],"tags":["apollo-portal","app-namespace","validation","duplicate"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}