apache/flink · error · ProgramInvocationException

Error while opening jar file '{jarFile.getPath()}'. {ioex.ge

Error message

Error while opening jar file '{jarFile.getPath()}'. {ioex.getMessage()}

What it means

Thrown by getEntryPointClassNameFromJar when new JarFile(...) raises an IOException while opening the jar file. The file exists as a path but cannot be read as a valid ZIP/JAR archive.

Source

Thrown at flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java:399

                    "An error occurred while invoking the program's main method: " + t.getMessage(),
                    t);
        }
    }

    private static String getEntryPointClassNameFromJar(URL jarFile)
            throws ProgramInvocationException {
        JarFile jar;
        Manifest manifest;
        String className;

        // Open jar file
        try {
            jar = new JarFile(new File(jarFile.toURI()));
        } catch (URISyntaxException use) {
            throw new ProgramInvocationException(
                    "Invalid file path '" + jarFile.getPath() + "'", use);
        } catch (IOException ioex) {
            throw new ProgramInvocationException(
                    "Error while opening jar file '"
                            + jarFile.getPath()
                            + "'. "
                            + ioex.getMessage(),
                    ioex);
        }

        // jar file must be closed at the end
        try {
            // Read from jar manifest
            try {
                manifest = jar.getManifest();
            } catch (IOException ioex) {
                throw new ProgramInvocationException(
                        "The Manifest in the jar file could not be accessed '"
                                + jarFile.getPath()
                                + "'. "
                                + ioex.getMessage(),

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Verify the file exists, is readable, and is a valid jar (unzip -l <jar> or jar tf <jar>).
  2. Re-download/rebuild the jar to rule out truncation or corruption.
  3. Check filesystem permissions for the Flink process on the jar path.
  4. Ensure the path points to a file, not a directory.
Defensive patterns

Strategy: validation

Validate before calling

if (!jarFile.isFile()) {
    throw new IllegalArgumentException("Not a regular file: " + jarFile);
}
if (!jarFile.canRead()) {
    throw new IllegalArgumentException("Jar not readable: " + jarFile);
}
// Sanity-check it is a ZIP
try (RandomAccessFile raf = new RandomAccessFile(jarFile, "r")) {
    long n = raf.length();
    raf.seek(n - 22);
    byte[] end = new byte[4]; raf.readFully(end);
    if (end[0] != 0x50 || end[1] != 0x4b) throw new IllegalArgumentException("Not a valid jar/zip");
}

Try / catch

try {
    PackagedProgram.newBuilder().setJarFile(jarFile).build();
} catch (ProgramInvocationException pie) {
    if (pie.getMessage().startsWith("Error while opening jar file")) {
        // verify file integrity / permissions, re-download
    }
    throw pie;
}

Prevention

When it happens

Trigger: The jar file path resolves but JarFile cannot open it: file not found, permission denied, truncated download, or the file is not a valid ZIP container.

Common situations: Incomplete jar download (truncated transfer); the path points to a directory or a plain file instead of a jar; filesystem permission issues; the jar was overwritten while being read.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/6c5e0567a4bf45ab. Report an issue: GitHub.