apolloconfig/apollo · error · BadRequestException

Failed to read file content.

Error message

Failed to read file content.

What it means

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).

Source

Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java:191

    ClusterDTO clusterDTO = clusterService.loadCluster(appId, env, clusterName);
    if (clusterDTO == null) {
      throw new BadRequestException(
          "The app does not exist in the specified environment and cluster.");
    }

    List<ImportNamespaceData> toImportNSs = Lists.newArrayList();
    ZipEntry entry;
    while ((entry = dataZip.getNextEntry()) != null) {
      if (entry.isDirectory()) {
        continue;
      }

      // file.path format :
      // ${appId}/${env}/${appId}+${cluster}+${namespaceName}
      String filePath = entry.getName();
      String content = readContent(dataZip);
      if (content == null) {
        throw new BadRequestException("Failed to read file content.");
      }
      String[] info = filePath.replace('\\', '/').split("/");
      if (info.length != 3) {
        throw new BadRequestException("Invalid file path in ZIP.");
      }
      String fileName = info[2];
      String fileNamePrefix = String.format("%s+%s+", appId, clusterName);

      if (!info[0].equals(appId) || !info[1].equalsIgnoreCase(env.getName())
          || !fileName.startsWith(fileNamePrefix)) {
        throw new BadRequestException("The content of the file to be imported is incorrect.");
      }
      if (!fileName.endsWith(ConfigFileUtils.CLUSTER_METADATA_FILE_SUFFIX)) {
        toImportNSs.add(new ImportNamespaceData(env, fileName, content, ignoreConflictNamespace));
      }
    }

    if (CollectionUtils.isEmpty(toImportNSs)) {

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Re-export the zip from the source Apollo environment to ensure integrity.
  2. Verify the zip file is not truncated or corrupted by testing it with a zip utility (unzip -t).
  3. Ensure the zip was created by Apollo's export functionality and not hand-assembled.
  4. Check network stability during file upload to the portal.
Defensive patterns

Strategy: validation

Validate before calling

// Validate zip integrity before import
ZipFile zipFile = new ZipFile(uploadedFile);
if (zipFile.size() == 0) {
  throw new IllegalArgumentException("Zip file contains no entries");
}
// Test each entry is readable
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
  ZipEntry entry = entries.nextElement();
  if (!entry.isDirectory()) {
    try (InputStream is = zipFile.getInputStream(entry)) {
      String content = new String(is.readAllBytes(), StandardCharsets.UTF_8);
      if (content.isEmpty()) {
        throw new IllegalArgumentException("Empty content in entry: " + entry.getName());
      }
    }
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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