{"record":{"id":"37be04b2ed58427d","repo":"apolloconfig/apollo","slug":"appnamespace-already-exists-as-public-namespace","errorCode":null,"errorMessage":"AppNamespace {} already exists as public namespace in appId: {}!","messagePattern":"AppNamespace (.+?) already exists as public namespace in appId: (.+?)!","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java","lineNumber":243,"sourceCode":"    if (!CollectionUtils.isEmpty(privateAppNamespaces)) {\n      Set<String> appIds = Sets.newHashSet();\n      for (AppNamespace ans : privateAppNamespaces) {\n        appIds.add(ans.getAppId());\n        if (appIds.size() == PRIVATE_APP_NAMESPACE_NOTIFICATION_COUNT) {\n          break;\n        }\n      }\n\n      throw new BadRequestException(\"Public AppNamespace \" + appNamespace.getName()\n          + \" already exists as private AppNamespace in appId: \" + APP_NAMESPACE_JOINER.join(appIds)\n          + \", etc. Please select another name!\");\n    }\n  }\n\n  private void checkPublicAppNamespaceGlobalUniqueness(AppNamespace appNamespace) {\n    AppNamespace publicAppNamespace = findPublicAppNamespace(appNamespace.getName());\n    if (publicAppNamespace != null) {\n      throw new BadRequestException(\"AppNamespace \" + appNamespace.getName()\n          + \" already exists as public namespace in appId: \" + publicAppNamespace.getAppId() + \"!\");\n    }\n  }\n\n  @ApolloAuditLog(type = OpType.DELETE, name = \"AppNamespace.delete\",\n      description = \"deleteAppNamespace\")\n  @Transactional\n  public AppNamespace deleteAppNamespace(String appId, String namespaceName, String operator) {\n    AppNamespace appNamespace = appNamespaceRepository.findByAppIdAndName(appId, namespaceName);\n    if (appNamespace == null) {\n      throw BadRequestException.appNamespaceNotExists(appId, namespaceName);\n    }\n\n    // this operator is passed to\n    // com.ctrip.framework.apollo.portal.listener.DeletionListener.onAppNamespaceDeletionEvent\n    appNamespace.setDataChangeLastModifiedBy(operator);\n\n    // delete app namespace in portal db","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java#L225-L261","documentation":"Thrown by checkPublicAppNamespaceGlobalUniqueness when a namespace name already exists as a PUBLIC namespace in another app (findPublicAppNamespace(name) != null). BadRequestException → HTTP 400. First {} is the namespace name; second is the appId that owns the existing public namespace. Public namespaces are globally unique by name.","triggerScenarios":"Creating/importing a namespace (public, or a private one that would collide) whose name matches an already-registered public namespace belonging to another app.","commonSituations":"Two apps attempt to claim the same public namespace name; re-importing a public namespace; renaming attempt that lands on an existing public name.","solutions":["Use findPublicAppNamespace(name) to check global availability before creating.","Reference the existing public namespace instead of creating a duplicate (link rather than re-create).","Choose a distinct name scoped to the owning app."],"exampleFix":"// before\nappNamespaceService.create(appNamespace);\n\n// after\nif (appNamespaceService.findPublicAppNamespace(appNamespace.getName()) != null) {\n  // link to existing public namespace instead of duplicating\n  return;\n}\nappNamespaceService.create(appNamespace);","handlingStrategy":"validation","validationCode":"if (appNamespaceService.findPublicAppNamespace(ns.getName()) != null) {\n  return ResponseEntity.badRequest().body(\"public namespace name already taken\");\n}","typeGuard":"boolean isPublicNameGloballyFree(String name, AppNamespaceService svc) {\n  return svc.findPublicAppNamespace(name) == null;\n}","tryCatchPattern":null,"preventionTips":["Public namespace names are globally unique; check findPublicAppNamespace first.","Reference existing public namespaces rather than re-creating them."],"tags":["apollo-portal","app-namespace","public-namespace","validation","naming-collision"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}