apolloconfig/apollo · warning · BadRequestException

Private AppNamespace {} already exists!

Error message

Private AppNamespace {} already exists!

What it means

Thrown during custom AppNamespace creation (the create() path) when a PRIVATE namespace with the same appId+name already exists in the repository (findByAppIdAndName != null). BadRequestException → HTTP 400. The {} is the namespace name substituted via string concatenation. After this check it also verifies the name does not collide with any PUBLIC namespace.

Source

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

    if (!ConfigFileFormat.isValidFormat(appNamespace.getFormat())) {
      throw BadRequestException
          .invalidNamespaceFormat("format must be properties、json、yaml、yml、xml");
    }

    if (StringUtils.isEmpty(appNamespace.getDataChangeCreatedBy())) {
      appNamespace.setDataChangeCreatedBy(operator);
    }

    appNamespace.setDataChangeLastModifiedBy(operator);

    // globally uniqueness check for public app namespace
    if (appNamespace.isPublic()) {
      checkAppNamespaceGlobalUniqueness(appNamespace);
    } else {
      // check private app namespace
      if (appNamespaceRepository.findByAppIdAndName(appNamespace.getAppId(),
          appNamespace.getName()) != null) {
        throw new BadRequestException(
            "Private AppNamespace " + appNamespace.getName() + " already exists!");
      }
      // should not have the same with public app namespace
      checkPublicAppNamespaceGlobalUniqueness(appNamespace);
    }

    AppNamespace createdAppNamespace = appNamespaceRepository.save(appNamespace);

    roleInitializationService.initNamespaceRoles(appNamespace.getAppId(), appNamespace.getName(),
        operator);
    roleInitializationService.initNamespaceEnvRoles(appNamespace.getAppId(), appNamespace.getName(),
        operator);

    return createdAppNamespace;
  }

  @Transactional
  public AppNamespace importAppNamespaceInLocal(AppNamespace appNamespace) {

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Check findByAppIdAndName(appId, name) == null before creating.
  2. Refresh the namespace list in the UI to avoid stale duplicate submissions.
  3. Choose a different namespace name if a duplicate is legitimately needed.

Example fix

// before
appNamespaceService.create(appNamespace);

// after
if (appNamespaceRepository.findByAppIdAndName(appNamespace.getAppId(), appNamespace.getName()) != null) {
  return existing; // or skip
}
appNamespaceService.create(appNamespace);
Defensive patterns

Strategy: validation

Validate before calling

if (appNamespaceRepository.findByAppIdAndName(ns.getAppId(), ns.getName()) != null) {
  return ResponseEntity.badRequest().body("namespace already exists");
}

Type guard

boolean isUniquePrivateNamespace(String appId, String name, AppNamespaceRepository repo) {
  return repo.findByAppIdAndName(appId, name) == null;
}

Prevention

When it happens

Trigger: Creating a private namespace whose appId+name pair already exists in the AppNamespace table; duplicate submission of the same namespace within one app.

Common situations: User clicks create twice; a previous successful creation was not reflected in the UI before retry; import tool re-runs over existing data.

Related errors


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