apolloconfig/apollo · warning · BadRequestException

release ids can not be empty

Error message

release ids can not be empty

What it means

BadRequestException (HTTP 400) from the @Deprecated InstanceController endpoint GET /envs/{env}/instances/by-namespace-and-releases-not-in. releaseIds is split on ',' with omitEmptyStrings+trimResults; if the resulting Set<Long> is empty the handler refuses. Important: a NON-numeric token (e.g. 'abc') throws NumberFormatException from Long::parseLong BEFORE this check, producing a different (500) error instead.

Source

Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/InstanceController.java:90

  public ResponseEntity<Number> getInstanceCountByNamespace(@PathVariable String env,
      @RequestParam String appId, @RequestParam String clusterName,
      @RequestParam String namespaceName) {

    int count = instanceService.getInstanceCountByNamespace(appId, Env.valueOf(env), clusterName,
        namespaceName);
    return ResponseEntity.ok(new Number(count));
  }

  @GetMapping("/envs/{env}/instances/by-namespace-and-releases-not-in")
  public List<InstanceDTO> getByReleasesNotIn(@PathVariable String env, @RequestParam String appId,
      @RequestParam String clusterName, @RequestParam String namespaceName,
      @RequestParam String releaseIds) {

    Set<Long> releaseIdSet = RELEASES_SPLITTER.splitToList(releaseIds).stream().map(Long::parseLong)
        .collect(Collectors.toSet());

    if (CollectionUtils.isEmpty(releaseIdSet)) {
      throw new BadRequestException("release ids can not be empty");
    }

    return instanceService.getByReleasesNotIn(Env.valueOf(env), appId, clusterName, namespaceName,
        releaseIdSet);
  }


}

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Pass at least one numeric release id, e.g. releaseIds=12 or releaseIds=12,34.
  2. Migrate to the documented OpenAPI endpoints; this controller is marked @Deprecated.
  3. Strip empty tokens client-side and assert all tokens are numeric (see validationCode) to avoid the NumberFormatException path.
  4. If you genuinely have no releases, short-circuit on the client instead of calling.

Example fix

// before
GET /envs/DEV/instances/by-namespace-and-releases-not-in?appId=...&releaseIds=

// after
GET /envs/DEV/instances/by-namespace-and-releases-not-in?appId=...&releaseIds=12,34
Defensive patterns

Strategy: validation

Validate before calling

// releaseIds: comma-separated, non-empty, all numeric. Matches the server splitter behavior.
static String normalizeReleaseIds(String raw) {
  if (raw == null) throw new IllegalArgumentException("release ids can not be empty");
  List<String> parts = Arrays.stream(raw.split(","))
      .map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toList());
  if (parts.isEmpty()) throw new IllegalArgumentException("release ids can not be empty");
  for (String p : parts) Long.parseLong(p); // throws -> caller gets a clear client error, not 500
  return String.join(",", parts);
}

Type guard

static boolean isValidReleaseIds(String raw) {
  if (raw == null) return false;
  boolean any = false;
  for (String p : raw.split(",")) {
    String t = p.trim();
    if (t.isEmpty()) continue;
    any = true;
    try { Long.parseLong(t); } catch (NumberFormatException e) { return false; }
  }
  return any;
}

Prevention

When it happens

Trigger: Calling the legacy by-namespace-and-releases-not-in endpoint with releaseIds empty, only commas, or omitted entirely (note releaseIds is a required @RequestParam, so omission yields a 400 'missing parameter' from Spring, not this message).

Common situations: Frontend passing an empty selection of releases; building the comma list from an empty array; leftover calls to the deprecated WebAPI after migrating to the OpenAPI equivalents.

Related errors


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