apache/beam · error

error opening jar for extractJar

Error message

error opening jar for extractJar(%s,%s): %w

What it means

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.

Solutions

  1. Delete the corrupt jar file and re-download it (verify size/checksum).
  2. Confirm the source path exists and is readable by the process user.
  3. Check that the download step succeeded (HTTP 200, full body copied) before extraction.
  4. Verify file integrity with `unzip -t <jar>`.

Example fix

// before
jarPath, err := expansionx.MakeJar(ctx, url, dest) // reuses corrupt cached jar
// after
if fi, err := os.Stat(cachedJar); err == nil && fi.Size() < 1<<20 {
    os.Remove(cachedJar) // suspiciously small: force re-download
}
jarPath, err := expansionx.MakeJar(ctx, url, dest)
Defensive patterns

Strategy: validation

Validate before calling

fi, err := os.Stat(source)
if err != nil { return fmt.Errorf("jar missing: %w", err) }
if fi.Size() == 0 { return fmt.Errorf("jar %s is empty; re-download", source) }
if b, _ := os.ReadFile(source); len(b) > 4 && !bytes.Equal(b[:2], []byte("PK")) {
    return fmt.Errorf("jar %s is not a zip archive", source)
}

Try / catch

jarPath, err := expansionx.MakeJar(ctx, url, dest)
if err != nil && strings.Contains(err.Error(), "error opening jar") {
    os.Remove(jarPath) // drop corrupt artifact
    jarPath, err = expansionx.MakeJar(ctx, url, dest)
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/04aa6f644c674028. Report an issue: GitHub.

Appendix: source

Thrown at sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go:157

	return jarPath, nil
}

func validatePath(dest, filename string) (string, error) {
	destPath := filepath.Join(dest, filename)
	cleanDest := filepath.Clean(dest)
	cleanPath := filepath.Clean(destPath)

	rel, err := filepath.Rel(cleanDest, cleanPath)
	if err != nil || strings.HasPrefix(rel, ".."+string(filepath.Separator)) || rel == ".." {
		return "", fmt.Errorf("file path %q is outside destination directory %q", filename, dest)
	}
	return cleanPath, nil
}

func extractJar(source, dest string) error {
	reader, err := zip.OpenReader(source)
	if err != nil {
		return fmt.Errorf("error opening jar for extractJar(%s,%s): %w", source, dest, err)
	}

	if err := os.MkdirAll(dest, 0700); err != nil {
		return fmt.Errorf("error creating directory %s in extractJar(%s,%s): %w", dest, source, dest, err)
	}

	for _, file := range reader.File {
		fileName, err := validatePath(dest, file.Name)
		if err != nil {
			return fmt.Errorf("error validating file path (%s, %s): %w", dest, file.Name, err)
		}
		if file.FileInfo().IsDir() {
			os.MkdirAll(fileName, 0700)
			continue
		}

		sf, err := file.Open()
		if err != nil {

View on GitHub (pinned to 12126d8942)