apolloconfig/apollo · warning · BadRequestException

Public AppNamespace {} already exists as private AppNamespac

Error message

Public AppNamespace {} already exists as private AppNamespace in appId: {}, etc. Please select another name!

What it means

Thrown by checkAppNamespaceGlobalUniqueness when creating a PUBLIC namespace whose name collides with one or more existing PRIVATE namespaces across apps. It lists up to PRIVATE_APP_NAMESPACE_NOTIFICATION_COUNT colliding appIds. BadRequestException → HTTP 400. First {} is the namespace name; second is the joined appId list. Public namespaces must be globally unique and must not shadow private ones.

Source

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

    return createdAppNamespace;
  }

  private void checkAppNamespaceGlobalUniqueness(AppNamespace appNamespace) {
    checkPublicAppNamespaceGlobalUniqueness(appNamespace);

    List<AppNamespace> privateAppNamespaces = findAllPrivateAppNamespaces(appNamespace.getName());

    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);

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Select a globally unique name for the public namespace (e.g. prefix with org/lib name).
  2. Query findAllPrivateAppNamespaces(name) first to detect collisions before attempting creation.
  3. If the private usages are stale, remove or rename them, then retry.

Example fix

// before
appNamespace.setPublic(true);
appNamespaceService.create(appNamespace);

// after
if (!appNamespaceService.findAllPrivateAppNamespaces(appNamespace.getName()).isEmpty()) {
  throw new IllegalStateException("name collides with private namespaces; choose another");
}
appNamespace.setPublic(true);
appNamespaceService.create(appNamespace);
Defensive patterns

Strategy: validation

Validate before calling

if (!appNamespaceService.findAllPrivateAppNamespaces(ns.getName()).isEmpty()) {
  return ResponseEntity.badRequest().body("name collides with private namespaces");
}

Type guard

boolean isPublicNameFreeOfPrivateCollisions(String name, AppNamespaceService svc) {
  return CollectionUtils.isEmpty(svc.findAllPrivateAppNamespaces(name));
}

Prevention

When it happens

Trigger: Creating/importing a public namespace whose name is already used as a private namespace in any app. The portal collects colliding appIds and reports them.

Common situations: Trying to promote a name already in private use to public; teams independently chose the same namespace name; shared-library namespace name collides with an app-private one.

Related errors


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