{"record":{"id":"f9f7ebcd43cdde81","repo":"apache/flink","slug":"could-not-create-a-valid-uri-from-the-given-file-p","errorCode":null,"errorMessage":"Could not create a valid URI from the given file path name: {}","messagePattern":"Could not create a valid URI from the given file path name: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/io/FileInputFormat.java","lineNumber":272,"sourceCode":"        if (filePath == null) {\n            throw new IllegalArgumentException(\"File path cannot be null.\");\n        }\n\n        // TODO The job-submission web interface passes empty args (and thus empty\n        // paths) to compute the preview graph. The following is a workaround for\n        // this situation and we should fix this.\n\n        // comment (Stephan Ewen) this should be no longer relevant with the current Java/Scala\n        // APIs.\n        if (filePath.isEmpty()) {\n            setFilePath(new Path());\n            return;\n        }\n\n        try {\n            this.setFilePath(new Path(filePath));\n        } catch (RuntimeException rex) {\n            throw new RuntimeException(\n                    \"Could not create a valid URI from the given file path name: \"\n                            + rex.getMessage());\n        }\n    }\n\n    /**\n     * Sets a single path of a file to be read.\n     *\n     * @param filePath The path of the file to read.\n     */\n    public void setFilePath(Path filePath) {\n        if (filePath == null) {\n            throw new IllegalArgumentException(\"File path must not be null.\");\n        }\n\n        setFilePaths(filePath);\n    }\n","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/io/FileInputFormat.java#L254-L290","documentation":"When setFilePath(String) constructs a new Path(filePath), the Path constructor can throw a RuntimeException (e.g. from URI parsing) if the string is malformed — missing scheme, illegal characters, unencodable segments. FileInputFormat catches that and rethrows as a RuntimeException with a clearer message indicating the path could not be turned into a valid URI.","triggerScenarios":"Passing a path string with illegal URI characters (spaces, unencoded special chars), a missing/misspelled scheme (e.g. 'hdfs:/data' with a single slash), or a relative path that the URI parser rejects.","commonSituations":"Windows paths with backslashes or drive letters; paths with spaces not percent-encoded; copy-pasting an S3/HDFS URL missing a slash; mixing local and distributed path styles.","solutions":["Use a fully-qualified, properly-encoded URI (e.g. 'hdfs:///data/input' or 'file:///abs/path').","Percent-encode spaces and special characters, or use the Path(URI) overload.","Construct the Path yourself with new Path(scheme, authority, path) and pass it to setFilePath(Path) to control parsing.","On local files use absolute paths under a 'file://' scheme."],"exampleFix":"// before\nformat.setFilePath(\"C:\\\\data\\\\input file.csv\"); // backslashes + space -> throws\n\n// after\nformat.setFilePath(\"file:///C:/data/input%20file.csv\");\n// or build a Path explicitly\nformat.setFilePath(new Path(\"file\", \"\", \"/C:/data/input file.csv\"));","handlingStrategy":"try-catch","validationCode":"// Pre-validate by constructing the Path and catching issues with a clearer message.\nPath p;\ntry {\n    p = new Path(pathString);\n} catch (RuntimeException e) {\n    throw new IllegalArgumentException(\"Invalid file path URI: \" + pathString, e);\n}\nformat.setFilePath(p);","typeGuard":null,"tryCatchPattern":"try {\n    format.setFilePath(pathString);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"valid URI\")) {\n        // log the offending path, suggest encoding, rethrow with context\n        throw new IllegalArgumentException(\"Cannot parse path '\" + pathString + \"'; use a fully-qualified, encoded URI\", e);\n    }\n    throw e;\n}","preventionTips":["Use fully-qualified URIs (scheme + authority + path).","Percent-encode spaces and special characters in path segments.","On Windows, prefer forward slashes and a 'file://' scheme."],"tags":["input-format","file-path","uri","path-parsing","runtime-exception"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}