apolloconfig/apollo · warning · BadRequestException

AppNamespace {} already exists as public namespace in appId:

Error message

AppNamespace {} already exists as public namespace in appId: {}!

What it means

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.

Source

Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java:243

    if (!CollectionUtils.isEmpty(privateAppNamespaces)) {
      Set<String> appIds = Sets.newHashSet();
      for (AppNamespace ans : privateAppNamespaces) {
        appIds.add(ans.getAppId());
        if (appIds.size() == PRIVATE_APP_NAMESPACE_NOTIFICATION_COUNT) {
          break;
        }
      }

      throw new BadRequestException("Public AppNamespace " + appNamespace.getName()
          + " already exists as private AppNamespace in appId: " + APP_NAMESPACE_JOINER.join(appIds)
          + ", etc. Please select another name!");
    }
  }

  private void checkPublicAppNamespaceGlobalUniqueness(AppNamespace appNamespace) {
    AppNamespace publicAppNamespace = findPublicAppNamespace(appNamespace.getName());
    if (publicAppNamespace != null) {
      throw new BadRequestException("AppNamespace " + appNamespace.getName()
          + " already exists as public namespace in appId: " + publicAppNamespace.getAppId() + "!");
    }
  }

  @ApolloAuditLog(type = OpType.DELETE, name = "AppNamespace.delete",
      description = "deleteAppNamespace")
  @Transactional
  public AppNamespace deleteAppNamespace(String appId, String namespaceName, String operator) {
    AppNamespace appNamespace = appNamespaceRepository.findByAppIdAndName(appId, namespaceName);
    if (appNamespace == null) {
      throw BadRequestException.appNamespaceNotExists(appId, namespaceName);
    }

    // this operator is passed to
    // com.ctrip.framework.apollo.portal.listener.DeletionListener.onAppNamespaceDeletionEvent
    appNamespace.setDataChangeLastModifiedBy(operator);

    // delete app namespace in portal db

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Use findPublicAppNamespace(name) to check global availability before creating.
  2. Reference the existing public namespace instead of creating a duplicate (link rather than re-create).
  3. Choose a distinct name scoped to the owning app.

Example fix

// before
appNamespaceService.create(appNamespace);

// after
if (appNamespaceService.findPublicAppNamespace(appNamespace.getName()) != null) {
  // link to existing public namespace instead of duplicating
  return;
}
appNamespaceService.create(appNamespace);
Defensive patterns

Strategy: validation

Validate before calling

if (appNamespaceService.findPublicAppNamespace(ns.getName()) != null) {
  return ResponseEntity.badRequest().body("public namespace name already taken");
}

Type guard

boolean isPublicNameGloballyFree(String name, AppNamespaceService svc) {
  return svc.findPublicAppNamespace(name) == null;
}

Prevention

When it happens

Trigger: Creating/importing a namespace (public, or a private one that would collide) whose name matches an already-registered public namespace belonging to another app.

Common situations: Two apps attempt to claim the same public namespace name; re-importing a public namespace; renaming attempt that lands on an existing public name.

Related errors


AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14). Data as JSON: /api/errors/37be04b2ed58427d. Report an issue: GitHub.