{"record":{"id":"2bdfa9b74c430159","repo":"elastic/elasticsearch","slug":"failed-to-patch-archive","errorCode":null,"errorMessage":"Failed to patch archive","messagePattern":"Failed to patch archive","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"build-tools/src/main/java/org/elasticsearch/gradle/transform/FilteringJarTransform.java","lineNumber":73,"sourceCode":"\n        try (\n            ZipFile input = new ZipFile(original);\n            ZipOutputStream output = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(transformed)))\n        ) {\n            Enumeration<? extends ZipEntry> entries = input.entries();\n            while (entries.hasMoreElements()) {\n                ZipEntry entry = entries.nextElement();\n                if (excludes.stream().noneMatch(e -> e.matches(Path.of(entry.getName())))) {\n                    output.putNextEntry(entry);\n                    input.getInputStream(entry).transferTo(output);\n                    output.closeEntry();\n                }\n            }\n\n            output.flush();\n            output.finish();\n        } catch (IOException e) {\n            throw new UncheckedIOException(\"Failed to patch archive\", e);\n        }\n    }\n\n    private List<PathMatcher> createMatchers(List<String> patterns) {\n        return patterns.stream().map(p -> FileSystems.getDefault().getPathMatcher(\"glob:\" + p)).toList();\n    }\n\n    public static void registerTransform(DependencyHandler dependencyHandler, Action<Parameters> config) {\n        dependencyHandler.registerTransform(FilteringJarTransform.class, spec -> {\n            spec.getFrom().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.JAR_TYPE);\n            spec.getTo().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, FILTERED_JAR_TYPE);\n            config.execute(spec.getParameters());\n        });\n    }\n\n    public abstract static class Parameters implements TransformParameters, Serializable {\n        private List<String> excludes = new ArrayList<>();\n","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools/src/main/java/org/elasticsearch/gradle/transform/FilteringJarTransform.java#L55-L91","documentation":"FilteringJarTransform throws an UncheckedIOException wrapping any IOException raised while reading the input jar, copying filtered entries, or finalizing the output jar. The transform reads each zip entry, skips entries matching any exclude glob, and streams the rest to a new jar; an I/O failure (corrupt input, disk full, interrupted stream) aborts with this generic message.","triggerScenarios":"The transform is registered to produce a 'filtered jar' artifact type from a standard jar. It fails if the input jar is corrupt/truncated, an entry can't be read, the output path isn't writable, or the process is interrupted mid-copy.","commonSituations":"A cached/downloaded dependency jar is partially downloaded (network blip); a snapshot jar overwritten mid-transform by another process; disk full in the Gradle build cache; a glob pattern whose PathMatcher throws; concurrent builds racing on the same transform output.","solutions":["Run `./gradlew --refresh-dependencies` to re-download potentially corrupt dependency jars.","Clear the transform's output cache (`rm -rf` the relevant `.gradle/caches/transforms-*` dir or run `--rerun-tasks`).","Check disk space and permissions on the Gradle user home and project build dirs.","Inspect the wrapped IOException's cause for the specific entry/path that failed; isolate whether it's one input jar or all."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  transform();\n} catch (UncheckedIOException e) {\n  if (e.getMessage().contains(\"Failed to patch archive\")) {\n    // purge the corrupt input from cache and retry once\n    cleanTransformCache(inputArtifact);\n  }\n  throw e;\n}","preventionTips":["Pin dependency versions to known-good artifacts to avoid re-downloading corrupt ones.","Run `--refresh-dependencies` after network instability.","Ensure the build/cache directory is on a writable, disk-space-sufficient volume."],"tags":["gradle","transform","io","dependencies","build-tools"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}