{"record":{"id":"e61a07383f44c4a7","repo":"apolloconfig/apollo","slug":"originalfilename-namespace-and-format-is-invalid","errorCode":null,"errorMessage":"{originalFilename} namespace and format is invalid!","messagePattern":"(.+?) namespace and format is invalid!","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java","lineNumber":137,"sourceCode":"    checkThreePart(originalFilename);\n    return getThreePart(originalFilename)[1];\n  }\n\n  /**\n   * <pre>\n   *  \"application+default+application.properties\" -> \"application\"\n   *  \"application+default+application.yml\" -> \"application.yml\"\n   *  \"application+default+application.json\" -> \"application.json\"\n   *  \"application+default+application.333.yml\" -> \"application.333.yml\"\n   * </pre>\n   * @throws BadRequestException if file's name is invalid\n   */\n  public static String getNamespace(final String originalFilename) {\n    checkThreePart(originalFilename);\n    final String[] threeParts = getThreePart(originalFilename);\n    final String suffix = threeParts[2];\n    if (!suffix.contains(\".\")) {\n      throw new BadRequestException(originalFilename + \" namespace and format is invalid!\");\n    }\n    final int lastDotIndex = suffix.lastIndexOf(\".\");\n    final String namespace = suffix.substring(0, lastDotIndex);\n    // format after last character '.'\n    final String format = suffix.substring(lastDotIndex + 1);\n    if (!ConfigFileFormat.isValidFormat(format)) {\n      throw new BadRequestException(originalFilename + \" format is invalid!\");\n    }\n    ConfigFileFormat configFileFormat = ConfigFileFormat.fromString(format);\n    if (configFileFormat.equals(ConfigFileFormat.Properties)) {\n      return namespace;\n    } else {\n      // compatibility of other format\n      return namespace + \".\" + format;\n    }\n  }\n\n  /**","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java#L119-L155","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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()."],"exampleFix":"// before — filename '666+default+application'\n// after — filename '666+default+application.properties'","handlingStrategy":"validation","validationCode":"String filename = file.getOriginalFilename();\nif (filename != null) {\n    String suffix = filename.split(\"\\\\+\")[2]; // assumes checkThreePart passed\n    if (!suffix.contains(\".\")) {\n        return ResponseEntity.badRequest().body(\"Namespace segment must include a format extension\");\n    }\n}","typeGuard":"static boolean suffixHasFormatSeparator(String filename) {\n    if (filename == null) return false;\n    String[] parts = filename.split(\"\\\\+\");\n    return parts.length == 3 && parts[2].contains(\".\");\n}","tryCatchPattern":"try {\n    String namespace = ConfigFileUtils.getNamespace(filename);\n} catch (BadRequestException e) {\n    if (e.getMessage().contains(\"namespace and format is invalid\")) {\n        return ResponseEntity.badRequest().body(\"Third segment needs a format extension (e.g., application.properties)\");\n    }\n    throw e;\n}","preventionTips":["Ensure the namespace segment (third '+' part) includes a dot-separated format.","Validate filename structure with toFilename() output as a reference template."],"tags":["apollo-portal","config-import","validation","bad-request"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}