apolloconfig/apollo · error · BadRequestException
{originalFilename} namespace and format is invalid!
Error message
{originalFilename} namespace and format is invalid! What it means
Thrown by ConfigFileUtils.getNamespace() at line 137 when the third '+' part of the filename (the suffix) contains no '.' character, making it impossible to split into namespace and format. For example, '666+default+application' — the third part 'application' has no dot, so there's no format separator. BadRequestException → HTTP 400. This is distinct from error 216 (wrong part count) — here the three-part split succeeded but the suffix is malformed.
Source
Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java:137
checkThreePart(originalFilename);
return getThreePart(originalFilename)[1];
}
/**
* <pre>
* "application+default+application.properties" -> "application"
* "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;
}
}
/**View on GitHub (pinned to d95fc18d11)
Solutions
- Ensure the third '+' part of the filename includes a format extension (e.g., 'application.properties', not 'application').
- Use toFilename(appId, cluster, namespace, ConfigFileFormat.Properties) to generate correct filenames.
- Validate that the suffix contains at least one '.' before calling getNamespace().
Example fix
// before — filename '666+default+application' // 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]; // assumes checkThreePart passed
if (!suffix.contains(".")) {
return ResponseEntity.badRequest().body("Namespace segment must include a format extension");
}
} Type guard
static boolean suffixHasFormatSeparator(String filename) {
if (filename == null) return false;
String[] parts = filename.split("\\+");
return parts.length == 3 && parts[2].contains(".");
} Try / catch
try {
String namespace = ConfigFileUtils.getNamespace(filename);
} catch (BadRequestException e) {
if (e.getMessage().contains("namespace and format is invalid")) {
return ResponseEntity.badRequest().body("Third segment needs a format extension (e.g., application.properties)");
}
throw e;
} Prevention
- Ensure the namespace segment (third '+' part) includes a dot-separated format.
- Validate filename structure with toFilename() output as a reference template.
When it happens
Trigger: Calling getNamespace() on a filename like '666+default+application' where the suffix (third '+' segment) lacks a '.'. The method needs to split the suffix at the last dot to separate namespace from format. No dot means no format is present.
Common situations: Filename follows the three-part '+' convention but the namespace segment is missing its format extension. Common when a Properties file is renamed without '.properties' or when a non-Properties format (which keeps its extension in the namespace) is uploaded without it.
Related errors
- The app does not exist in the specified environment and clus
- The file is empty. {originalFilename}
- The file format is invalid.
- file name [{originalFilename}] not valid
- {originalFilename} format is invalid!
AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14).
Data as JSON: /api/errors/e61a07383f44c4a7.
Report an issue: GitHub.