apolloconfig/apollo · warning · BadRequestException
App already has application namespace. AppId = %s
Error message
App already has application namespace. AppId = %s
What it means
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.
Source
Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java:106
public AppNamespace findByAppIdAndName(String appId, String namespaceName) {
return appNamespaceRepository.findByAppIdAndName(appId, namespaceName);
}
public List<AppNamespace> findByAppId(String appId) {
return appNamespaceRepository.findByAppId(appId);
}
public List<AppNamespace> findAll() {
Iterable<AppNamespace> appNamespaces = appNamespaceRepository.findAll();
return Lists.newArrayList(appNamespaces);
}
@ApolloAuditLog(type = OpType.CREATE, name = "AppNamespace.create",
description = "createDefaultAppNamespace")
@Transactional
public void createDefaultAppNamespace(String appId, String operator) {
if (!isAppNamespaceNameUnique(appId, ConfigConsts.NAMESPACE_APPLICATION)) {
throw new BadRequestException("App already has application namespace. AppId = %s", appId);
}
AppNamespace appNs = new AppNamespace();
appNs.setAppId(appId);
appNs.setName(ConfigConsts.NAMESPACE_APPLICATION);
appNs.setComment("default app namespace");
appNs.setFormat(ConfigFileFormat.Properties.getValue());
appNs.setDataChangeCreatedBy(operator);
appNs.setDataChangeLastModifiedBy(operator);
appNamespaceRepository.save(appNs);
}
public boolean isAppNamespaceNameUnique(String appId, String namespaceName) {
Objects.requireNonNull(appId, "AppId must not be null");
Objects.requireNonNull(namespaceName, "Namespace must not be null");
return Objects.isNull(appNamespaceRepository.findByAppIdAndName(appId, namespaceName));
}View on GitHub (pinned to d95fc18d11)
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.
Example fix
// before
appNamespaceService.createDefaultAppNamespace(appId, operator);
// after
if (appNamespaceService.isAppNamespaceNameUnique(appId, ConfigConsts.NAMESPACE_APPLICATION)) {
appNamespaceService.createDefaultAppNamespace(appId, operator);
} Defensive patterns
Strategy: validation
Validate before calling
if (!appNamespaceService.isAppNamespaceNameUnique(appId, ConfigConsts.NAMESPACE_APPLICATION)) {
return; // default namespace already exists
} Type guard
boolean shouldCreateDefaultNamespace(String appId, AppNamespaceService svc) {
return svc.isAppNamespaceNameUnique(appId, ConfigConsts.NAMESPACE_APPLICATION);
} Prevention
- Make app-creation idempotent: check the default namespace exists before creating.
- Avoid re-running creation flows after partial commits without a cleanup step.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Private AppNamespace {} already exists!
- AppId not equal. AppId in path = %s, AppId in payload = %s
- Public AppNamespace {} already exists as private AppNamespac
- AppNamespace {} already exists as public namespace in appId:
- userIds should not be null or empty
AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14).
Data as JSON: /api/errors/85c60ea068e5f422.
Report an issue: GitHub.