{"record":{"id":"9eea5dade05d5eb8","repo":"junit-team/junit5","slug":"file-s-could-not-be-read","errorCode":null,"errorMessage":"File [%s] could not be read","messagePattern":"File \\[(.+?)\\] could not be read","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvFileArgumentsProvider.java","lineNumber":178,"sourceCode":"\n\t\tprivate static final DefaultInputStreamProvider INSTANCE = new DefaultInputStreamProvider();\n\n\t\t@Override\n\t\tpublic InputStream openClasspathResource(Class<?> baseClass, String path) {\n\t\t\tPreconditions.notBlank(path, () -> \"Classpath resource [\" + path + \"] must not be null or blank\");\n\t\t\t//noinspection resource (closed elsewhere)\n\t\t\tInputStream inputStream = baseClass.getResourceAsStream(path);\n\t\t\treturn Preconditions.notNull(inputStream, () -> \"Classpath resource [\" + path + \"] does not exist\");\n\t\t}\n\n\t\t@Override\n\t\tpublic InputStream openFile(String path) {\n\t\t\tPreconditions.notBlank(path, () -> \"File [\" + path + \"] must not be null or blank\");\n\t\t\ttry {\n\t\t\t\treturn Files.newInputStream(Path.of(path));\n\t\t\t}\n\t\t\tcatch (IOException e) {\n\t\t\t\tthrow new JUnitException(\"File [\" + path + \"] could not be read\", e);\n\t\t\t}\n\t\t}\n\n\t}\n\n}\n","sourceCodeStart":160,"sourceCodeEnd":185,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvFileArgumentsProvider.java#L160-L185","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n@CsvFileSource(files = \"testdata/input.csv\")\n\n// after (classpath)\n@CsvFileSource(resources = \"/testdata/input.csv\")\n// or absolute path\n@CsvFileSource(files = \"/abs/path/to/input.csv\")","handlingStrategy":"validation","validationCode":"// Verify the file exists and is readable before the test runs\nPath p = Path.of(csvFilePath);\nif (!Files.isRegularFile(p) || !Files.isReadable(p))\n    throw new IllegalArgumentException(\"CSV file not readable: \" + p);","typeGuard":"static boolean isReadableCsvFile(String path) {\n    Path p = Path.of(path);\n    return Files.isRegularFile(p) && Files.isReadable(p);\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["junit-jupiter","csv","file-io","configuration"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}