apache/flink · error · IllegalArgumentException

The jar file path is invalid.

Error message

The jar file path is invalid.

What it means

Thrown when the jar file path provided to PackagedProgram cannot be converted to a valid URL. The conversion File.getAbsoluteFile().toURI().toURL() threw a MalformedURLException, indicating the path contains characters or constructs that are illegal in a URI/URL context. This is an IllegalArgumentException, wrapping a lower-level JDK failure.

Source

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

        } finally {
            try {
                jar.close();
            } catch (Throwable t) {
                throw new ProgramInvocationException(
                        "Could not close the JAR file: " + t.getMessage(), t);
            }
        }
    }

    @Nullable
    private static URL loadJarFile(File jar) throws ProgramInvocationException {
        if (jar != null) {
            URL jarFileUrl;

            try {
                jarFileUrl = jar.getAbsoluteFile().toURI().toURL();
            } catch (MalformedURLException e1) {
                throw new IllegalArgumentException("The jar file path is invalid.");
            }

            checkJarFile(jarFileUrl);

            return jarFileUrl;
        } else {
            return null;
        }
    }

    private static Class<?> loadMainClass(String className, ClassLoader cl)
            throws ProgramInvocationException {
        ClassLoader contextCl = null;
        try {
            contextCl = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(cl);
            return Class.forName(className, false, cl);
        } catch (ClassNotFoundException e) {

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Verify the jar file path is a valid absolute or relative filesystem path with no illegal URI characters.
  2. Ensure the File object is constructed from a clean path string (no stray quotes, protocols, or null segments).
  3. Test the path with File.getAbsoluteFile().toURI().toURL() in isolation to reproduce the MalformedURLException.

Example fix

// before
File jarFile = new File(rawUserInput);
PackagedProgram.newBuilder().setJarFile(jarFile).build();

// after
File jarFile = new File(rawUserInput.trim());
jarFile.getAbsoluteFile().toURI().toURL(); // validate before passing
PackagedProgram.newBuilder().setJarFile(jarFile).build();
Defensive patterns

Strategy: validation

Validate before calling

File jarFile = new File(path);
if (!jarFile.exists() || !jarFile.isFile()) {
    throw new IllegalArgumentException("Jar file does not exist or is not a file: " + path);
}
try {
    jarFile.getAbsoluteFile().toURI().toURL();
} catch (MalformedURLException e) {
    throw new IllegalArgumentException("Jar path produces invalid URL: " + path, e);
}

Try / catch

try {
    PackagedProgram.newBuilder().setJarFile(jarFile).build();
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("jar file path is invalid")) {
        // handle invalid path
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling PackagedProgram.newBuilder().setJarFile(jarFile) with a File whose path contains characters that break URI conversion (e.g., spaces encoded incorrectly, special characters, or a malformed path). The error fires inside loadJarFile before any jar validation occurs.

Common situations: Paths with unusual characters on Windows, symlinks resolving to odd paths, or programmatic construction of a File from an invalid string. Most commonly seen when a path is assembled from user input without sanitization.

Related errors


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