apolloconfig/apollo · error · BadRequestException

AppId is null or blank

Error message

AppId is null or blank

What it means

Thrown by AppController.createApp after confirming the app object is non-null but its appId field is blank (null, empty, or whitespace-only). The appId is the primary identifier for an Apollo application and must be provided at creation time. StringUtils.hasText(app.getAppId()) returns false for null, "", or " ". Results in HTTP 400.

Source

Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/AppController.java:96

    this.userInfoHolder = userInfoHolder;
    this.rolePermissionService = rolePermissionService;
    this.unifiedPermissionValidator = unifiedPermissionValidator;
  }

  /**
   * @see com.ctrip.framework.apollo.portal.controller.AppController#create(AppModel)
   */
  @Transactional
  @PreAuthorize(value = "@unifiedPermissionValidator.hasCreateApplicationPermission()")
  @ApolloAuditLog(type = OpType.CREATE, name = "App.create")
  @Override
  public ResponseEntity<Void> createApp(OpenCreateAppDTO req) {
    if (null == req.getApp()) {
      throw new BadRequestException("App is null");
    }
    final OpenAppDTO app = req.getApp();
    if (!StringUtils.hasText(app.getAppId())) {
      throw new BadRequestException("AppId is null or blank");
    }
    validatePortalApp(app);
    String resolvedOperator = resolveOperator(app.getDataChangeCreatedBy());
    app.setDataChangeCreatedBy(resolvedOperator);
    app.setDataChangeLastModifiedBy(resolvedOperator);
    this.appOpenApiService.createApp(req, resolvedOperator);
    if (Boolean.TRUE.equals(req.getAssignAppRoleToSelf())
        && UserIdentityConstants.CONSUMER.equals(UserIdentityContextHolder.getAuthType())) {
      long consumerId = this.consumerAuthUtil.retrieveConsumerIdFromCtx();
      consumerService.assignAppRoleToConsumer(consumerId, app.getAppId(), resolvedOperator);
    }
    return ResponseEntity.ok().build();
  }

  @Override
  public ResponseEntity<List<OpenEnvClusterInfo>> getEnvClusterInfo(String appId) {
    requireReadApplicationPermissionForUserToken(appId);
    if (!hasReadApplicationPermissionForCurrentIdentity(appId)) {

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Provide a non-blank appId in the app object — it must match the pattern [0-9a-zA-Z_-]+[0-9a-zA-Z_.-]*.
  2. Generate the appId deterministically (e.g., project prefix + sequence) before sending the request.
  3. Check for typos in the JSON field name (camelCase appId, not app_id).

Example fix

// before
OpenAppDTO app = new OpenAppDTO();
app.setName("My App");
// appId not set

// after
OpenAppDTO app = new OpenAppDTO();
app.setAppId("my-app-001");
app.setName("My App");
Defensive patterns

Strategy: validation

Validate before calling

// Validate appId is present before creating the app
OpenAppDTO app = req.getApp();
if (app.getAppId() == null || app.getAppId().trim().isEmpty()) {
    throw new IllegalArgumentException("appId must not be null or blank");
}

Type guard

public static boolean hasValidAppId(OpenAppDTO app) {
    return app != null && app.getAppId() != null && !app.getAppId().trim().isEmpty();
}

Prevention

When it happens

Trigger: Sending a create-app request where the app object exists but appId is missing, empty, or contains only whitespace. For example: {"app": {"name": "My App"}} without an appId field.

Common situations: A client assumes the server will auto-generate the appId, but Apollo requires it upfront. The appId field was populated from a variable that evaluated to null at runtime. JSON key naming mismatch (e.g., app_id vs appId).

Related errors


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