{"record":{"id":"4ad7832d73887f82","repo":"arduino/Arduino","slug":"error-while-extracting-file-outputfile-getabsolut","errorCode":null,"errorMessage":"Error while extracting file {outputFile.getAbsolutePath()}","messagePattern":"Error while extracting file (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"arduino-core/src/cc/arduino/utils/ArchiveExtractor.java","lineNumber":294,"sourceCode":"    FileOutputStream fos = null;\n    try {\n      fos = new FileOutputStream(outputFile);\n      // if size is not available, copy until EOF...\n      if (size == -1) {\n        byte buffer[] = new byte[4096];\n        int length;\n        while ((length = in.read(buffer)) != -1) {\n          fos.write(buffer, 0, length);\n        }\n        return;\n      }\n\n      // ...else copy just the needed amount of bytes\n      byte buffer[] = new byte[4096];\n      while (size > 0) {\n        int length = in.read(buffer);\n        if (length <= 0) {\n          throw new IOException(\"Error while extracting file \" + outputFile.getAbsolutePath());\n        }\n        fos.write(buffer, 0, length);\n        size -= length;\n      }\n    } finally {\n      IOUtils.closeQuietly(fos);\n    }\n  }\n\n}\n","sourceCodeStart":276,"sourceCodeEnd":305,"githubUrl":"https://github.com/arduino/Arduino/blob/a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee/arduino-core/src/cc/arduino/utils/ArchiveExtractor.java#L276-L305","documentation":"During extraction, copyStreamToFile throws this IOException when the archive input stream returns <= 0 bytes (EOF) while the entry still has bytes remaining to copy. It means the archive is truncated, corrupt, or the underlying stream was interrupted mid-entry.","triggerScenarios":"extract() is copying a file entry of known size; in.read(buffer) returns -1 or 0 while size > 0, i.e. the stream ends before all expected bytes of the entry are read.","commonSituations":"Corrupted or partially downloaded archive file (e.g. failed library/platform download); archive modified or truncated during extraction; reading a compressed stream from a closed or failing source.","solutions":["Verify the archive integrity (re-download or re-copy the file and check its checksum) and retry extraction","Ensure the source stream/file is not being written or truncated concurrently while extracting","Check that the archive is a valid zip/tar supported by the compressor used (correct compressionMethod)","Free disk space if the volume filled up mid-extraction, then retry"],"exampleFix":"// before\ndownloader.downloadFile(url, archiveFile, false);\nextractor.extract(archiveFile, outputDir);\n// after: verify before extracting\nif (archiveFile.length() < expectedMinSize) throw new IOException(\"archive truncated\");\nextractor.extract(archiveFile, outputDir);","handlingStrategy":"validation","validationCode":"if (!archiveFile.exists() || archiveFile.length() == 0)\n  throw new IllegalStateException(\"Archive missing/empty: \" + archiveFile);\n// optionally verify known checksum before extracting","typeGuard":null,"tryCatchPattern":"try {\n  extractor.extract(archive, dir);\n} catch (IOException e) {\n  if (e.getMessage().startsWith(\"Error while extracting file\")) {\n    // re-download the archive; it is truncated/corrupt\n    reDownload(archive);\n  } else throw e;\n}","preventionTips":["Always verify archive checksum/size after downloading before extracting","Never extract an archive that is still being written","Treat any interrupted download as invalid and discard it"],"tags":["io","archive-extraction","corrupt-archive","stream"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee","analyzedAt":"2026-09-06T10:13:38.901Z","contentChangedAt":"2026-09-06T10:13:38.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}