apolloconfig/apollo · error · BadRequestException

{originalFilename} format is invalid!

Error message

{originalFilename} format is invalid!

What it means

Thrown by ConfigFileUtils.getNamespace() at line 144 when the format extracted from the filename's suffix (the substring after the last '.') is not a valid ConfigFileFormat. The format string is checked via ConfigFileFormat.isValidFormat(). For example, '666+default+application.txt' — 'txt' is not a supported Apollo config format. Supported formats include: properties, yml, yaml, json, xml, txt (as a namespace suffix), and others per ConfigFileFormat enum. BadRequestException → HTTP 400.

Source

Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java:144

   *  "application+default+application.yml" -> "application.yml"
   *  "application+default+application.json" -> "application.json"
   *  "application+default+application.333.yml" -> "application.333.yml"
   * </pre>
   * @throws BadRequestException if file's name is invalid
   */
  public static String getNamespace(final String originalFilename) {
    checkThreePart(originalFilename);
    final String[] threeParts = getThreePart(originalFilename);
    final String suffix = threeParts[2];
    if (!suffix.contains(".")) {
      throw new BadRequestException(originalFilename + " namespace and format is invalid!");
    }
    final int lastDotIndex = suffix.lastIndexOf(".");
    final String namespace = suffix.substring(0, lastDotIndex);
    // format after last character '.'
    final String format = suffix.substring(lastDotIndex + 1);
    if (!ConfigFileFormat.isValidFormat(format)) {
      throw new BadRequestException(originalFilename + " format is invalid!");
    }
    ConfigFileFormat configFileFormat = ConfigFileFormat.fromString(format);
    if (configFileFormat.equals(ConfigFileFormat.Properties)) {
      return namespace;
    } else {
      // compatibility of other format
      return namespace + "." + format;
    }
  }

  /**
   * <pre>
   *   appId    cluster   namespace       return
   *   666      default   application     666+default+application.properties
   *   123      none      action.yml      123+none+action.yml
   * </pre>
   */
  public static String toFilename(final String appId, final String clusterName,

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Use a supported Apollo config file extension: properties, yml, yaml, json, xml, or other formats recognized by ConfigFileFormat.
  2. Check ConfigFileFormat.isValidFormat(extension) before importing.
  3. Convert the file to a supported format before upload.

Example fix

// before — filename '666+default+application.csv'
// after — filename '666+default+application.properties'
Defensive patterns

Strategy: validation

Validate before calling

String filename = file.getOriginalFilename();
if (filename != null) {
    String suffix = filename.split("\\+")[2];
    String format = suffix.substring(suffix.lastIndexOf('.') + 1);
    if (!ConfigFileFormat.isValidFormat(format)) {
        return ResponseEntity.badRequest().body("Unsupported format: " + format);
    }
}

Type guard

static boolean hasValidConfigFormat(String filename) {
    if (filename == null) return false;
    String[] parts = filename.split("\\+");
    if (parts.length != 3 || !parts[2].contains(".")) return false;
    String format = parts[2].substring(parts[2].lastIndexOf('.') + 1);
    return ConfigFileFormat.isValidFormat(format);
}

Try / catch

try {
    String namespace = ConfigFileUtils.getNamespace(filename);
} catch (BadRequestException e) {
    if (e.getMessage().contains("format is invalid")) {
        return ResponseEntity.badRequest().body("Use a supported format extension (properties, yml, yaml, json, xml)");
    }
    throw e;
}

Prevention

When it happens

Trigger: Uploading a config file whose extension doesn't correspond to a valid Apollo ConfigFileFormat. For example, '.csv', '.ini', '.conf', or '.log'. The suffix is split at the last dot and the format portion is passed to ConfigFileFormat.isValidFormat(), which rejects unknown formats.

Common situations: User uploads a file with an unsupported extension. File has a double extension like '.config.yml' where the last segment happens to be invalid (though 'yml' would be valid). Apollo version doesn't support a newer format the user is trying to import.

Related errors


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