apache/flink · error · IllegalArgumentException

JAR file path invalid

Error message

JAR file path invalid

What it means

In JarUtils.getJarFiles, each raw path string is converted with new File(jarPath).getAbsoluteFile().toURI().toURL(). If that throws MalformedURLException, this IllegalArgumentException ('JAR file path invalid') wraps it. With File-based conversion this is rare, but it fires for degenerate path inputs that cannot form a URL (e.g. null-like or malformed path fragments after the URL encoding step).

Source

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

                    "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) {
                                throw new IllegalArgumentException("JAR file path invalid", e);
                            } catch (IOException e) {
                                throw new RuntimeException("Problem with jar file " + jarPath, e);
                            }
                        })
                .collect(Collectors.toList());
    }
}

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Pass plain filesystem paths (absolute or relative) to getJarFiles, not URLs or URI fragments.
  2. Validate inputs before the call: reject null/empty strings and strings with illegal path characters.
  3. Log the offending jarPath when catching to identify which entry in the array failed.
  4. Prefer new File(jarPath).toURI().toURL() yourself if you need URL semantics, so failure points are explicit.

Example fix

// before
List<URL> jars = JarUtils.getJarFiles(new String[] {"file:/opt/lib/a b.jar"});

// after
List<URL> jars = JarUtils.getJarFiles(new String[] {"/opt/lib/a b.jar"}); // plain path, File handles encoding
Defensive patterns

Strategy: validation

Validate before calling

for (String jar : jars) {
    if (jar == null || jar.isBlank()) {
        throw new IllegalArgumentException("jar path must be a non-empty filesystem path");
    }
}
List<URL> urls = JarUtils.getJarFiles(jars);

Try / catch

try {
    return JarUtils.getJarFiles(jars);
} catch (IllegalArgumentException e) {
    // identify and report the offending path element
}

Prevention

When it happens

Trigger: Calling JarUtils.getJarFiles(String[]) with a path string that File.toURI().toURL() rejects — essentially only reachable with malformed/URI-illegal inputs, since File-based URL construction almost never throws MalformedURLException; treat it as a defensive guard on untrusted path strings.

Common situations: Programmatic callers passing unvalidated user input (e.g. parsed CLI args or config values) into getJarFiles; a path containing characters that break URI syntax; historically, code that passed URL-ish strings ('http://...') where a filesystem path was expected.

Related errors


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