{"record":{"id":"d9edacc3a0faf8e1","repo":"apolloconfig/apollo","slug":"failed-to-read-file-content","errorCode":null,"errorMessage":"Failed to read file content.","messagePattern":"Failed to read file content\\.","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java","lineNumber":191,"sourceCode":"    ClusterDTO clusterDTO = clusterService.loadCluster(appId, env, clusterName);\n    if (clusterDTO == null) {\n      throw new BadRequestException(\n          \"The app does not exist in the specified environment and cluster.\");\n    }\n\n    List<ImportNamespaceData> toImportNSs = Lists.newArrayList();\n    ZipEntry entry;\n    while ((entry = dataZip.getNextEntry()) != null) {\n      if (entry.isDirectory()) {\n        continue;\n      }\n\n      // file.path format :\n      // ${appId}/${env}/${appId}+${cluster}+${namespaceName}\n      String filePath = entry.getName();\n      String content = readContent(dataZip);\n      if (content == null) {\n        throw new BadRequestException(\"Failed to read file content.\");\n      }\n      String[] info = filePath.replace('\\\\', '/').split(\"/\");\n      if (info.length != 3) {\n        throw new BadRequestException(\"Invalid file path in ZIP.\");\n      }\n      String fileName = info[2];\n      String fileNamePrefix = String.format(\"%s+%s+\", appId, clusterName);\n\n      if (!info[0].equals(appId) || !info[1].equalsIgnoreCase(env.getName())\n          || !fileName.startsWith(fileNamePrefix)) {\n        throw new BadRequestException(\"The content of the file to be imported is incorrect.\");\n      }\n      if (!fileName.endsWith(ConfigFileUtils.CLUSTER_METADATA_FILE_SUFFIX)) {\n        toImportNSs.add(new ImportNamespaceData(env, fileName, content, ignoreConflictNamespace));\n      }\n    }\n\n    if (CollectionUtils.isEmpty(toImportNSs)) {","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java#L173-L209","documentation":"Thrown as a BadRequestException by ConfigsImportService.importAppConfigFromZipFile() when readContent(dataZip) returns null for a zip entry. readContent reads the current ZipEntry's bytes into a String; returning null indicates an I/O failure reading the entry content (e.g., corrupted zip entry, decompression error).","triggerScenarios":"Importing a zip file where one or more entries have corrupted content that readContent() cannot decode. The while-loop iterates entries; for any entry where readContent returns null, this exception fires immediately.","commonSituations":"Zip file was truncated during download/transfer; zip created by a non-Apollo tool with incompatible compression; the zip was modified after export; encoding issues in entry content.","solutions":["Re-export the zip from the source Apollo environment to ensure integrity.","Verify the zip file is not truncated or corrupted by testing it with a zip utility (unzip -t).","Ensure the zip was created by Apollo's export functionality and not hand-assembled.","Check network stability during file upload to the portal."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate zip integrity before import\nZipFile zipFile = new ZipFile(uploadedFile);\nif (zipFile.size() == 0) {\n  throw new IllegalArgumentException(\"Zip file contains no entries\");\n}\n// Test each entry is readable\nEnumeration<? extends ZipEntry> entries = zipFile.entries();\nwhile (entries.hasMoreElements()) {\n  ZipEntry entry = entries.nextElement();\n  if (!entry.isDirectory()) {\n    try (InputStream is = zipFile.getInputStream(entry)) {\n      String content = new String(is.readAllBytes(), StandardCharsets.UTF_8);\n      if (content.isEmpty()) {\n        throw new IllegalArgumentException(\"Empty content in entry: \" + entry.getName());\n      }\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate zip integrity before upload using a zip testing tool.","Re-export from the source environment if the zip is corrupted.","Ensure stable network during file upload to prevent truncation."],"tags":["apollo-portal","config-import","zip","bad-request","io"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}