{"id":"03925fce1032b2f0","repo":"junit-team/junit5","slug":"file-path-could-not-be-read","errorCode":null,"errorMessage":"File [${path}] 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/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvFileArgumentsProvider.java#L160-L185","documentation":"DefaultInputStreamProvider.openFile opens the path via Files.newInputStream(Path.of(path)) and wraps IOException in a JUnitException. A path listed in the @CsvFileSource.files array does not exist, is not a regular file, or is not readable.","triggerScenarios":"@CsvFileSource(files = {\"...\"}) where the path cannot be resolved relative to the JVM working directory, the file was deleted, or the process lacks read permission.","commonSituations":"Relative path resolved against an unexpected cwd (IDE vs CI build); typo in the path; confusing files (filesystem) with resources (classpath); permission denied.","solutions":["Put the file on the classpath and use the resources attribute instead of files.","Use an absolute path or confirm the relative path against System.getProperty(\"user.dir\").","Verify with Files.isReadable(Path.of(path)) before running the suite.","Check read permissions on the target file."],"exampleFix":"// before (cwd-dependent, fragile)\n@CsvFileSource(files = { \"data.csv\" })\n\n// after (classpath, portable)\n@CsvFileSource(resources = { \"/com/acme/data.csv\" })","handlingStrategy":"validation","validationCode":"// Confirm the file exists and is readable before the suite starts.\njava.nio.file.Path p = java.nio.file.Path.of(\"data.csv\");\nif (!java.nio.file.Files.isReadable(p)) {\n    throw new IllegalStateException(\"CSV file not readable: \" + p.toAbsolutePath());\n}","typeGuard":null,"tryCatchPattern":"try {\n    // run the CSV-file parameterized test\n} catch (JUnitException e) {\n    if (e.getMessage().contains(\"could not be read\")) {\n        // move the file to the classpath and switch files -> resources, or fix the path\n    } else throw e;\n}","preventionTips":["Prefer classpath resources over filesystem paths for test data.","Resolve relative paths explicitly against a known base directory.","Add a build-time check that the data files exist in the expected location."],"tags":["junit","jupiter-params","csv","file-io","configuration"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}