junit-team/junit5 · error · JUnitException
File [%s] could not be read
Error message
File [%s] could not be read
What it means
Thrown by the openFile(String) path source of CsvFileArgumentsProvider when Files.newInputStream(Path.of(path)) raises an IOException. The message names the path that could not be read and chains the IOException as cause. This is distinct from the classpath resource check, which fails earlier with a different message.
Source
Thrown at junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvFileArgumentsProvider.java:178
private static final DefaultInputStreamProvider INSTANCE = new DefaultInputStreamProvider();
@Override
public InputStream openClasspathResource(Class<?> baseClass, String path) {
Preconditions.notBlank(path, () -> "Classpath resource [" + path + "] must not be null or blank");
//noinspection resource (closed elsewhere)
InputStream inputStream = baseClass.getResourceAsStream(path);
return Preconditions.notNull(inputStream, () -> "Classpath resource [" + path + "] does not exist");
}
@Override
public InputStream openFile(String path) {
Preconditions.notBlank(path, () -> "File [" + path + "] must not be null or blank");
try {
return Files.newInputStream(Path.of(path));
}
catch (IOException e) {
throw new JUnitException("File [" + path + "] could not be read", e);
}
}
}
}
View on GitHub (pinned to f070c699a0)
Solutions
- Use an absolute path or verify the working directory; for classpath files prefer resources = ... instead of files = ...
- Confirm the file exists and is a regular file: Files.isRegularFile(Path.of(path)).
- Fix filesystem permissions so the test process can read the file.
- Move the data into src/test/resources and reference it via resources to avoid path issues.
Example fix
// before @CsvFileSource(files = "testdata/input.csv") // after (classpath) @CsvFileSource(resources = "/testdata/input.csv") // or absolute path @CsvFileSource(files = "/abs/path/to/input.csv")
Defensive patterns
Strategy: validation
Validate before calling
// Verify the file exists and is readable before the test runs
Path p = Path.of(csvFilePath);
if (!Files.isRegularFile(p) || !Files.isReadable(p))
throw new IllegalArgumentException("CSV file not readable: " + p); Type guard
static boolean isReadableCsvFile(String path) {
Path p = Path.of(path);
return Files.isRegularFile(p) && Files.isReadable(p);
} Prevention
- Prefer classpath resources via @CsvFileSource(resources = ...) to avoid path issues.
- Use absolute paths or anchor relative paths to the project directory in CI.
- Add a build-time check that committed CSV fixtures exist.
When it happens
Trigger: Providing @CsvFileSource(files = "...") with a path that does not exist, is a directory, or is not readable by the process. The openFile implementation catches IOException and wraps it as JUnitException.
Common situations: Relative file path resolved against an unexpected working directory. Missing or moved test data file. Permission denied on the file in CI. Path points to a directory rather than a file.
Related errors
- The charset supplied in %s is invalid
- Timeout duration is not in the expected format (<number> [ns
- Failed to parse CSV input configured via %s
- %s must be used with an annotation of type %s
- Assumption failed
AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11).
Data as JSON: /api/errors/9eea5dade05d5eb8.
Report an issue: GitHub.