{"record":{"id":"85c60ea068e5f422","repo":"apolloconfig/apollo","slug":"app-already-has-application-namespace-appid-s","errorCode":null,"errorMessage":"App already has application namespace. AppId = %s","messagePattern":"App already has application namespace\\. AppId = (.+?)","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java","lineNumber":106,"sourceCode":"  public AppNamespace findByAppIdAndName(String appId, String namespaceName) {\n    return appNamespaceRepository.findByAppIdAndName(appId, namespaceName);\n  }\n\n  public List<AppNamespace> findByAppId(String appId) {\n    return appNamespaceRepository.findByAppId(appId);\n  }\n\n  public List<AppNamespace> findAll() {\n    Iterable<AppNamespace> appNamespaces = appNamespaceRepository.findAll();\n    return Lists.newArrayList(appNamespaces);\n  }\n\n  @ApolloAuditLog(type = OpType.CREATE, name = \"AppNamespace.create\",\n      description = \"createDefaultAppNamespace\")\n  @Transactional\n  public void createDefaultAppNamespace(String appId, String operator) {\n    if (!isAppNamespaceNameUnique(appId, ConfigConsts.NAMESPACE_APPLICATION)) {\n      throw new BadRequestException(\"App already has application namespace. AppId = %s\", appId);\n    }\n\n    AppNamespace appNs = new AppNamespace();\n    appNs.setAppId(appId);\n    appNs.setName(ConfigConsts.NAMESPACE_APPLICATION);\n    appNs.setComment(\"default app namespace\");\n    appNs.setFormat(ConfigFileFormat.Properties.getValue());\n    appNs.setDataChangeCreatedBy(operator);\n    appNs.setDataChangeLastModifiedBy(operator);\n\n    appNamespaceRepository.save(appNs);\n  }\n\n  public boolean isAppNamespaceNameUnique(String appId, String namespaceName) {\n    Objects.requireNonNull(appId, \"AppId must not be null\");\n    Objects.requireNonNull(namespaceName, \"Namespace must not be null\");\n    return Objects.isNull(appNamespaceRepository.findByAppIdAndName(appId, namespaceName));\n  }","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java#L88-L124","documentation":"Thrown by AppNamespaceService.createDefaultAppNamespace when an 'application' namespace already exists for the given appId (isAppNamespaceNameUnique returns false). BadRequestException → HTTP 400. The %s is substituted with the appId via Strings.lenientFormat. This guards against duplicate creation of the built-in application namespace during app creation.","triggerScenarios":"Calling createDefaultAppNamespace(appId, operator) for an appId that already has the 'application' namespace — typically a re-run of app creation, or a retry after a partial failure that already saved the namespace.","commonSituations":"App-creation flow retried after the namespace step partially committed; manual/scripted provisioning that re-invokes default-namespace creation; migration/import that re-imports an app whose namespace already exists.","solutions":["Skip createDefaultAppNamespace when the app already has the 'application' namespace (check isAppNamespaceNameUnique first).","Make provisioning idempotent: query existence before creating.","If the app record is stale/orphaned, clean up the partial namespace then re-run."],"exampleFix":"// before\nappNamespaceService.createDefaultAppNamespace(appId, operator);\n\n// after\nif (appNamespaceService.isAppNamespaceNameUnique(appId, ConfigConsts.NAMESPACE_APPLICATION)) {\n  appNamespaceService.createDefaultAppNamespace(appId, operator);\n}","handlingStrategy":"validation","validationCode":"if (!appNamespaceService.isAppNamespaceNameUnique(appId, ConfigConsts.NAMESPACE_APPLICATION)) {\n  return; // default namespace already exists\n}","typeGuard":"boolean shouldCreateDefaultNamespace(String appId, AppNamespaceService svc) {\n  return svc.isAppNamespaceNameUnique(appId, ConfigConsts.NAMESPACE_APPLICATION);\n}","tryCatchPattern":null,"preventionTips":["Make app-creation idempotent: check the default namespace exists before creating.","Avoid re-running creation flows after partial commits without a cleanup step."],"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"}