{"record":{"id":"04aa6f644c674028","repo":"apache/beam","slug":"error-opening-jar-for-extractjar-s-s-w","errorCode":null,"errorMessage":"error opening jar for extractJar(%s,%s): %w","messagePattern":"error opening jar for extractJar\\((.+?),(.+?)\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go","lineNumber":157,"sourceCode":"\treturn jarPath, nil\n}\n\nfunc validatePath(dest, filename string) (string, error) {\n\tdestPath := filepath.Join(dest, filename)\n\tcleanDest := filepath.Clean(dest)\n\tcleanPath := filepath.Clean(destPath)\n\n\trel, err := filepath.Rel(cleanDest, cleanPath)\n\tif err != nil || strings.HasPrefix(rel, \"..\"+string(filepath.Separator)) || rel == \"..\" {\n\t\treturn \"\", fmt.Errorf(\"file path %q is outside destination directory %q\", filename, dest)\n\t}\n\treturn cleanPath, nil\n}\n\nfunc extractJar(source, dest string) error {\n\treader, err := zip.OpenReader(source)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error opening jar for extractJar(%s,%s): %w\", source, dest, err)\n\t}\n\n\tif err := os.MkdirAll(dest, 0700); err != nil {\n\t\treturn fmt.Errorf(\"error creating directory %s in extractJar(%s,%s): %w\", dest, source, dest, err)\n\t}\n\n\tfor _, file := range reader.File {\n\t\tfileName, err := validatePath(dest, file.Name)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error validating file path (%s, %s): %w\", dest, file.Name, err)\n\t\t}\n\t\tif file.FileInfo().IsDir() {\n\t\t\tos.MkdirAll(fileName, 0700)\n\t\t\tcontinue\n\t\t}\n\n\t\tsf, err := file.Open()\n\t\tif err != nil {","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go#L139-L175","documentation":"extractJar opens the downloaded jar with zip.OpenReader(source); this error wraps that failure. Since jars are zip files, a failure here means the file is missing, unreadable, or not a valid zip — most often because an earlier download step left a truncated or corrupt file.","triggerScenarios":"zip.OpenReader(source) fails during extractJar called from MakeJar: source path doesn't exist, permission denied, or the bytes are not a zip archive (e.g. an HTML error page saved as .jar).","commonSituations":"A previous failed download saved an error page as the jar; the jar was deleted by a cleanup job mid-pipeline; wrong path passed to MakeJar.","solutions":["Delete the corrupt jar file and re-download it (verify size/checksum).","Confirm the source path exists and is readable by the process user.","Check that the download step succeeded (HTTP 200, full body copied) before extraction.","Verify file integrity with `unzip -t <jar>`."],"exampleFix":"// before\njarPath, err := expansionx.MakeJar(ctx, url, dest) // reuses corrupt cached jar\n// after\nif fi, err := os.Stat(cachedJar); err == nil && fi.Size() < 1<<20 {\n    os.Remove(cachedJar) // suspiciously small: force re-download\n}\njarPath, err := expansionx.MakeJar(ctx, url, dest)","handlingStrategy":"validation","validationCode":"fi, err := os.Stat(source)\nif err != nil { return fmt.Errorf(\"jar missing: %w\", err) }\nif fi.Size() == 0 { return fmt.Errorf(\"jar %s is empty; re-download\", source) }\nif b, _ := os.ReadFile(source); len(b) > 4 && !bytes.Equal(b[:2], []byte(\"PK\")) {\n    return fmt.Errorf(\"jar %s is not a zip archive\", source)\n}","typeGuard":null,"tryCatchPattern":"jarPath, err := expansionx.MakeJar(ctx, url, dest)\nif err != nil && strings.Contains(err.Error(), \"error opening jar\") {\n    os.Remove(jarPath) // drop corrupt artifact\n    jarPath, err = expansionx.MakeJar(ctx, url, dest)\n}","preventionTips":["Validate downloads (HTTP 200 + full body) before caching.","Run `unzip -t` on cached jars as a health check in setup scripts.","Avoid cleanup jobs that delete jars while pipelines run.","Confirm downloaded bytes start with the PK zip magic."],"tags":["go","filesystem","zip","corrupt-file"],"backgroundTag":"file-open-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"}