{"record":{"id":"8fb87002220e8c38","repo":"apache/flink","slug":"invalid-file-path-jarfile-getpath","errorCode":null,"errorMessage":"Invalid file path '{jarFile.getPath()}'","messagePattern":"Invalid file path '(.+?)'","errorType":"exception","errorClass":"ProgramInvocationException","httpStatus":null,"severity":"error","filePath":"flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java","lineNumber":396,"sourceCode":"            }\n        } catch (Throwable t) {\n            throw new ProgramInvocationException(\n                    \"An error occurred while invoking the program's main method: \" + t.getMessage(),\n                    t);\n        }\n    }\n\n    private static String getEntryPointClassNameFromJar(URL jarFile)\n            throws ProgramInvocationException {\n        JarFile jar;\n        Manifest manifest;\n        String className;\n\n        // Open jar file\n        try {\n            jar = new JarFile(new File(jarFile.toURI()));\n        } catch (URISyntaxException use) {\n            throw new ProgramInvocationException(\n                    \"Invalid file path '\" + jarFile.getPath() + \"'\", use);\n        } catch (IOException ioex) {\n            throw new ProgramInvocationException(\n                    \"Error while opening jar file '\"\n                            + jarFile.getPath()\n                            + \"'. \"\n                            + ioex.getMessage(),\n                    ioex);\n        }\n\n        // jar file must be closed at the end\n        try {\n            // Read from jar manifest\n            try {\n                manifest = jar.getManifest();\n            } catch (IOException ioex) {\n                throw new ProgramInvocationException(\n                        \"The Manifest in the jar file could not be accessed '\"","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java#L378-L414","documentation":"Thrown by getEntryPointClassNameFromJar when new File(jarFile.toURI()) raises URISyntaxException. The jar file URL cannot be converted to a valid URI/File, so the manifest cannot be read to discover the main class.","triggerScenarios":"The jarFile URL passed to getEntryPointClassNameFromJar contains characters that are illegal in a URI (unescaped spaces, special characters, or a non-file scheme that breaks toURI()).","commonSituations":"Job jar paths containing spaces or non-ASCII characters on Windows; jar URLs constructed manually with illegal syntax; a URL of a non-file scheme being passed where a file: URL is expected.","solutions":["Move/rename the jar to a path without spaces or special characters.","Construct the jar URL via File.toURI().toURL() rather than string concatenation, ensuring proper escaping.","Ensure the URL uses the 'file' scheme.","On Windows, prefer forward-slash paths and avoid drive-letter edge cases."],"exampleFix":"// before: manual string URL with a space\nURL u = new URL(\"file:/C:/My Dir/job.jar\"); // -> URISyntaxException in toURI()\n\n// after: derive from File\nURL u = new File(\"C:/My Dir/job.jar\").toURI().toURL();","handlingStrategy":"validation","validationCode":"// Validate the jar URL is a well-formed file URI before submission\ntry {\n    URI u = jarFileUrl.toURI();\n    if (!\"file\".equalsIgnoreCase(u.getScheme())) {\n        throw new IllegalArgumentException(\"Jar URL is not a file: URI: \" + u);\n    }\n    File f = new File(u);\n    if (!f.isFile()) throw new IllegalArgumentException(\"Not a file: \" + f);\n} catch (URISyntaxException use) {\n    throw new IllegalArgumentException(\"Invalid jar URI\", use);\n}","typeGuard":null,"tryCatchPattern":"try {\n    PackagedProgram.newBuilder().setJarFile(jarFile).build();\n} catch (ProgramInvocationException pie) {\n    if (pie.getMessage().startsWith(\"Invalid file path\")) {\n        // sanitize the path: remove spaces, rebuild URL from File\n    }\n    throw pie;\n}","preventionTips":["Always derive jar URLs from File.toURI().toURL() rather than string concatenation.","Keep jar paths free of spaces and non-ASCII characters.","Prefer forward-slash paths, especially on Windows."],"tags":["packaged-program","jar","uri","path"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}