{"record":{"id":"e5e9ff540fc4cef9","repo":"apolloconfig/apollo","slug":"the-file-is-empty-originalfilename","errorCode":null,"errorMessage":"The file is empty. {originalFilename}","messagePattern":"The file is empty\\. (.+?)","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java","lineNumber":56,"sourceCode":" */\npublic class ConfigFileUtils {\n\n  public static final String APP_METADATA_FILENAME = \"app.metadata\";\n  public static final String CLUSTER_METADATA_FILE_SUFFIX = \".cluster.metadata\";\n  public static final String APP_NAMESPACE_METADATA_FILE_SUFFIX = \".appnamespace.metadata\";\n\n  public static void check(MultipartFile file) {\n    checkEmpty(file);\n    final String originalFilename = file.getOriginalFilename();\n    checkFormat(originalFilename);\n  }\n\n  /**\n   * @throws BadRequestException if file is empty\n   */\n  static void checkEmpty(MultipartFile file) {\n    if (file.isEmpty()) {\n      throw new BadRequestException(\"The file is empty. \" + file.getOriginalFilename());\n    }\n  }\n\n  /**\n   * @throws BadRequestException if file's format is invalid\n   */\n  static void checkFormat(final String originalFilename) {\n    final List<String> fileNameSplit = Splitter.on(\".\").splitToList(originalFilename);\n    if (fileNameSplit.size() <= 1) {\n      throw new BadRequestException(\"The file format is invalid.\");\n    }\n\n    for (String s : fileNameSplit) {\n      if (StringUtils.isEmpty(s)) {\n        throw new BadRequestException(\"The file format is invalid.\");\n      }\n    }\n  }","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java#L38-L74","documentation":"Thrown by ConfigFileUtils.checkEmpty() when MultipartFile.isEmpty() returns true. Called from check() which is the entry point for config file import validation. The original filename is appended to the message for diagnostics. BadRequestException → HTTP 400. This fires before format and three-part checks.","triggerScenarios":"Uploading a config file via the import endpoint (ConfigsImportController) where the MultipartFile has no content — zero bytes, or the client sent an empty file body. For example, selecting a file in the UI that was truncated to zero bytes, or an API POST with an empty multipart body.","commonSituations":"Client uploads a file that was deleted or truncated between selection and submission. Network issue results in an empty body. Test script creates a temporary file but writes nothing. File picker on some OS allows selecting a 0-byte file.","solutions":["Ensure the uploaded file has content before submitting.","Add client-side validation to check file.size > 0 before upload.","If importing programmatically, verify the file is non-empty before attaching to the multipart request."],"exampleFix":"// before — uploading a zero-byte file\n// after — client-side check\nif (file.size === 0) { alert('File is empty'); return; }","handlingStrategy":"validation","validationCode":"if (file == null || file.isEmpty()) {\n    return ResponseEntity.badRequest().body(\"File is empty or missing\");\n}\nConfigFileUtils.check(file);","typeGuard":"static boolean isNonEmptyFile(MultipartFile file) {\n    return file != null && !file.isEmpty();\n}","tryCatchPattern":"try {\n    ConfigFileUtils.check(file);\n} catch (BadRequestException e) {\n    if (e.getMessage().contains(\"file is empty\")) {\n        return ResponseEntity.badRequest().body(\"Upload a non-empty file\");\n    }\n    throw e;\n}","preventionTips":["Validate file.getSize() > 0 on the client before upload.","Check file existence and content before attaching to the multipart request."],"tags":["apollo-portal","config-import","file-upload","validation","bad-request"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}