apache/flink · error · IllegalArgumentException
File path must not be null.
Error message
File path must not be null.
What it means
The Path overload of FileInputFormat.setFilePath delegates to setFilePaths(filePath) after a null check. A null Path cannot be resolved to a filesystem location, so it is rejected with IllegalArgumentException. This guards the typed entry point that the String overload (error 312) feeds into.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/common/io/FileInputFormat.java:285
}
try {
this.setFilePath(new Path(filePath));
} catch (RuntimeException rex) {
throw new RuntimeException(
"Could not create a valid URI from the given file path name: "
+ rex.getMessage());
}
}
/**
* Sets a single path of a file to be read.
*
* @param filePath The path of the file to read.
*/
public void setFilePath(Path filePath) {
if (filePath == null) {
throw new IllegalArgumentException("File path must not be null.");
}
setFilePaths(filePath);
}
/**
* Sets multiple paths of files to be read.
*
* @param filePaths The paths of the files to read.
*/
public void setFilePaths(String... filePaths) {
Path[] paths = new Path[filePaths.length];
for (int i = 0; i < paths.length; i++) {
paths[i] = new Path(filePaths[i]);
}
setFilePaths(paths);
}
View on GitHub (pinned to 2f3c205e92)
Solutions
- Construct and pass a non-null Path, e.g. format.setFilePath(new Path(uri)).
- Validate with Preconditions.checkNotNull(path, ...) before calling setFilePath.
- Prefer the String overload when you only have a string, so the URI-error message is clearer.
Example fix
// before Path p = maybeResolvePath(); // null format.setFilePath(p); // throws // after Path p = Preconditions.checkNotNull(maybeResolvePath(), "path must be resolved"); format.setFilePath(p);
Defensive patterns
Strategy: validation
Validate before calling
Path p = Preconditions.checkNotNull(resolvedPath, "path must be resolved"); format.setFilePath(p);
Prevention
- Resolve paths eagerly and null-check before setFilePath.
- Use Preconditions.checkNotNull with a descriptive message.
- Prefer the String overload for friendlier URI error messages.
When it happens
Trigger: Calling format.setFilePath((Path) null); passing a Path variable that was constructed from null parts or never assigned.
Common situations: Building the path conditionally and forgetting the branch that leaves it null; chaining new Path(null); refactoring that drops the assignment.
Related errors
- File path cannot be null.
- At least one file path must be specified.
- The block size parameter must be set and larger than 0.
- Delimiter must not be null
- Line length limit must be at least 1.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/2bd9b479f47a0027.
Report an issue: GitHub.