apache/flink · error · IOException

Error while opening jar file '{}'

Error message

Error while opening jar file '{}'

What it means

The final check in JarUtils.checkJarFile: the path is a valid URI, the file exists and is readable, but constructing java.util.jar.JarFile over it throws IOException. This means the file is not a valid zip/jar container (corrupt, truncated, or a different format) or the jar is invalid for the JVM's strictness settings.

Source

Thrown at flink-core/src/main/java/org/apache/flink/util/JarUtils.java:55

    public static void checkJarFile(URL jar) throws IOException {
        File jarFile;
        try {
            jarFile = new File(jar.toURI());
        } catch (URISyntaxException e) {
            throw new IOException("JAR file path is invalid '" + jar + '\'');
        }
        if (!jarFile.exists()) {
            throw new IOException("JAR file does not exist '" + jarFile.getAbsolutePath() + '\'');
        }
        if (!jarFile.canRead()) {
            throw new IOException("JAR file can't be read '" + jarFile.getAbsolutePath() + '\'');
        }

        try (JarFile ignored = new JarFile(jarFile)) {
            // verify that we can open the Jar file
        } catch (IOException e) {
            throw new IOException(
                    "Error while opening jar file '" + jarFile.getAbsolutePath() + '\'', e);
        }
    }

    public static List<URL> getJarFiles(final String[] jars) {
        if (jars == null) {
            return Collections.emptyList();
        }

        return Arrays.stream(jars)
                .map(
                        jarPath -> {
                            try {
                                final URL fileURL =
                                        new File(jarPath).getAbsoluteFile().toURI().toURL();
                                JarUtils.checkJarFile(fileURL);
                                return fileURL;
                            } catch (MalformedURLException e) {

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Inspect the cause exception (zip error details) and verify the file: run 'jar tf file.jar' or 'unzip -t file.jar' to confirm it is a valid archive.
  2. Re-download or re-transfer the jar in binary mode from a trusted source and verify its checksum (sha512sum).
  3. If git LFS is used, run 'git lfs pull' so pointer placeholders become real binaries.
  4. Regenerate the jar from a clean build if it was produced by a failed/partial packaging step.

Example fix

# before
$ jar tf connector.jar
java.util.zip.ZipException: zip END header not found

# after (re-download and verify)
$ curl -O https://repo.example/connector.jar
$ sha512sum -c connector.jar.sha512
$ jar tf connector.jar   # lists entries OK
Defensive patterns

Strategy: validation

Validate before calling

// Cheap integrity probe before checkJarFile
try (java.util.jar.JarFile probe = new java.util.jar.JarFile(new File(jarUrl.toURI()))) {
    probe.stream().findFirst(); // forces central-directory parse
}
JarUtils.checkJarFile(jarUrl);

Prevention

When it happens

Trigger: Calling JarUtils.checkJarFile on a file that exists and is readable but is not a well-formed jar: a partially downloaded jar, an HTML error page saved with a .jar extension, a zip64 jar rejected by the JVM, or a file corrupted in transfer.

Common situations: Interrupted download or truncated artifact from a repository mirror; a proxy served an HTML 403 page saved as the jar name; jars corrupted by git LFS pointer files not being pulled; FTP/SCP transfer in ASCII mode mangling binary bytes.

Related errors


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