{"record":{"id":"aad8874a9653d23d","repo":"apache/beam","slug":"error-in-extractjar-w","errorCode":null,"errorMessage":"error in extractJar(): %w","messagePattern":"error in extractJar\\(\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go","lineNumber":285,"sourceCode":"\t\t} else {\n\t\t\treturn \"\", fmt.Errorf(\"error in getLocal(): %w\", err)\n\t\t}\n\t}\n\n\t// classpath jars should have relative path\n\trelClasspath := []string{}\n\tfor _, path := range classpathJars {\n\t\trelPath, err := filepath.Rel(cacheDir, path)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"error in creating relative path: %w\", err)\n\t\t}\n\t\trelClasspath = append(relClasspath, relPath)\n\t}\n\n\ttmpDir := filepath.Join(cacheDir, \"tmpDir\")\n\n\tif err := extractJar(mainJar, tmpDir); err != nil {\n\t\treturn \"\", fmt.Errorf(\"error in extractJar(): %w\", err)\n\t}\n\n\tmanifest, err := os.ReadFile(tmpDir + \"/META-INF/MANIFEST.MF\")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error readingf: %w\", err)\n\t}\n\n\t// trim the empty lines present at the end of MANIFEST.MF file.\n\tmanifestLines := strings.Split(string(manifest), \"\\n\")\n\tmanifestLines = manifestLines[:len(manifestLines)-2]\n\n\tclasspathString := fmt.Sprintf(\"%sClass-Path: %s\\n\", strings.Join(manifestLines, \"\\n\"), strings.Join(relClasspath, \" \"))\n\tif err = os.WriteFile(tmpDir+\"/META-INF/MANIFEST.MF\", []byte(classpathString), 0660); err != nil {\n\t\treturn \"\", fmt.Errorf(\"error writing ta manifest file: %w\", err)\n\t}\n\n\tpath, err := os.Getwd()\n\tif err != nil {","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go#L267-L303","documentation":"MakeJar wraps any failure from extractJar(), which unzips the downloaded Beam JAR into a temp directory so its MANIFEST.MF can be rewritten with a relocated Class-Path. A non-nil error from extractJar (zip open/read/write failure) is wrapped here with the standard Go %w pattern so callers can unwrap the root cause.","triggerScenarios":"MakeJar is called (via startAutomatedJavaExpansionService) and extractJar fails: the main JAR file does not exist at the expected cache path, the file is not a valid zip archive, or the destination tmpDir cannot be created/written.","commonSituations":"A partial or corrupted JAR was left in the cache from an earlier failed download; disk full or permission problems on the cache directory; the JAR path computed by GetBeamJar points at a non-zip file.","solutions":["Delete the cached JAR and tmpDir under cacheDir and re-run so a fresh JAR is downloaded.","Check disk space and write permissions on the cache directory.","Unwrap the error (errors.Unwrap / errors.As on *zip.Error) to see whether the JAR is corrupt or the destination is unwritable.","Verify the JAR was fetched from the repository correctly (non-truncated download)."],"exampleFix":"// before: blindly reusing possibly-corrupt cache\njar, err := expansionx.MakeJar(ctx, gradleTarget, repoURL, version)\n// after: verify zip integrity before MakeJar\nif _, err := zip.OpenReader(jarPath); err != nil {\n    os.RemoveAll(filepath.Join(cacheDir, \"tmpDir\"))\n    os.Remove(jarPath) // force fresh download\n}\njar, err := expansionx.MakeJar(ctx, gradleTarget, repoURL, version)","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(mainJar); err != nil {\n    return fmt.Errorf(\"main jar missing: %w\", err)\n}\nif _, err := zip.OpenReader(mainJar); err != nil {\n    os.Remove(mainJar) // corrupt cache entry, force re-download\n}","typeGuard":"func isZipError(err error) bool {\n    var ze *zip.Error\n    return errors.As(err, &ze)\n}","tryCatchPattern":"jar, err := expansionx.MakeJar(ctx, target, repo, version)\nif err != nil && strings.Contains(err.Error(), \"error in extractJar()\") {\n    os.RemoveAll(cacheDir) // clear cache and retry once\n    jar, err = expansionx.MakeJar(ctx, target, repo, version)\n}","preventionTips":["Clear the JAR cache after failed/interrupted downloads.","Monitor disk space on the cache volume.","Run the expansion service as a user that owns the cache directory."],"tags":["go","zip","jar-extraction","file-system"],"backgroundTag":"file-read-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}