{"record":{"id":"3917783216fc3251","repo":"spring-projects/spring-boot","slug":"error-packaging-archive-for-image","errorCode":null,"errorMessage":"Error packaging archive for image","messagePattern":"Error packaging archive for image","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java","lineNumber":441,"sourceCode":"\n\t\tprivate final ImagePackager packager;\n\n\t\tPackagedTarArchive(Owner owner, Libraries libraries, ImagePackager packager) {\n\t\t\tthis.owner = owner;\n\t\t\tthis.libraries = libraries;\n\t\t\tthis.packager = packager;\n\t\t}\n\n\t\t@Override\n\t\tpublic void writeTo(OutputStream outputStream) throws IOException {\n\t\t\tTarArchiveOutputStream tar = new TarArchiveOutputStream(outputStream);\n\t\t\ttar.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);\n\t\t\ttry {\n\t\t\t\tthis.packager.packageImage(this.libraries, (entry, entryWriter) -> write(entry, entryWriter, tar));\n\t\t\t}\n\t\t\tcatch (RuntimeException ex) {\n\t\t\t\toutputStream.close();\n\t\t\t\tthrow new RuntimeException(\"Error packaging archive for image\", ex);\n\t\t\t}\n\t\t}\n\n\t\tprivate void write(ZipEntry jarEntry, @Nullable EntryWriter entryWriter, TarArchiveOutputStream tar) {\n\t\t\ttry {\n\t\t\t\tTarArchiveEntry tarEntry = convert(jarEntry);\n\t\t\t\ttar.putArchiveEntry(tarEntry);\n\t\t\t\tif (tarEntry.isFile()) {\n\t\t\t\t\tAssert.state(entryWriter != null, \"'entryWriter' must not be null\");\n\t\t\t\t\tentryWriter.write(tar);\n\t\t\t\t}\n\t\t\t\ttar.closeArchiveEntry();\n\t\t\t}\n\t\t\tcatch (IOException ex) {\n\t\t\t\tthrow new IllegalStateException(ex);\n\t\t\t}\n\t\t}\n","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java#L423-L459","documentation":"RuntimeException thrown by PackagedTarArchive.writeTo while converting a packaged jar/war into the tar stream consumed by the image builder. packageImage iterates jar entries and writes each as a TarArchiveEntry via the write helper; any RuntimeException from packaging, entry conversion, or stream writes is caught, the OutputStream is closed, and the cause is re-wrapped for clarity.","triggerScenarios":"A RuntimeException during ImagePackager.packageImage or while writing individual entries (e.g., ZipEntry→TarArchiveEntry conversion failure, null entryWriter on a file entry, duplicate entry, corrupted source archive). Triggered at build-image time.","commonSituations":"Corrupt or truncated input jar (often from an interrupted previous package); non-standard archive contents the converter can't handle; concurrent writes to the same tar; disk full mid-stream surfacing as an unchecked exception; entry larger than allowed tar limits.","solutions":["Inspect the wrapped cause — it usually names the specific entry or operation that failed.","Re-run `mvn clean package` to regenerate a known-good archive before build-image.","Verify the source jar/war opens cleanly (`jar tf target/*.jar`).","If using a custom ImagePackager customization, ensure entryWriters are non-null for file entries."],"exampleFix":"// before: mvn spring-boot:build-image   (against a stale/corrupt target/*.jar)\n// after:  mvn clean package spring-boot:build-image","handlingStrategy":"try-catch","validationCode":"// Verify the input archive is well-formed before build-image:\ntry (JarFile jf = new JarFile(archiveFile)) {\n    // iterate a few entries; any exception means a corrupt jar\n    Enumeration<JarEntry> e = jf.entries();\n    while (e.hasMoreElements()) { jf.getInputStream(e.nextElement()).close(); }\n}","typeGuard":null,"tryCatchPattern":"try {\n    // invoke build-image\n} catch (RuntimeException ex) {\n    if (\"Error packaging archive for image\".equals(ex.getMessage())) {\n        Throwable cause = ex.getCause(); // the per-entry failure\n    }\n    throw ex;\n}","preventionTips":["Run `mvn clean package` immediately before build-image to avoid stale/corrupt archives.","Don't customize ImagePackager in ways that drop entryWriter for file entries.","Validate `jar tf target/*.jar` opens cleanly in CI."],"tags":["spring-boot","maven-plugin","build-image","tar","packaging"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}