{"record":{"id":"3b8e4e4e61036faf","repo":"perwendel/spark","slug":"description-cannot-be-resolved-to-absolute-file","errorCode":null,"errorMessage":"${description} cannot be resolved to absolute file path because it does not reside in the file system","messagePattern":"(.+?) cannot be resolved to absolute file path because it does not reside in the file system","errorType":"exception","errorClass":"java.io.FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/main/java/spark/utils/ResourceUtils.java","lineNumber":170,"sourceCode":"     * Resolve the given resource location to a {@code java.io.File},\n     * i.e. to a file in the file system.\n     * <p>Does not check whether the file actually exists; simply returns\n     * the File that the given location would correspond to.\n     *\n     * @param resourceLocation the resource location to resolve: either a\n     *                         \"classpath:\" pseudo URL, a \"file:\" URL, or a plain file path\n     * @return a corresponding File object\n     * @throws FileNotFoundException if the resource cannot be resolved to\n     *                               a file in the file system\n     */\n    public static File getFile(String resourceLocation) throws FileNotFoundException {\n        Assert.notNull(resourceLocation, \"Resource location must not be null\");\n        if (resourceLocation.startsWith(CLASSPATH_URL_PREFIX)) {\n            String path = resourceLocation.substring(CLASSPATH_URL_PREFIX.length());\n            String description = \"class path resource [\" + path + \"]\";\n            URL url = ClassUtils.getDefaultClassLoader().getResource(path);\n            if (url == null) {\n                throw new FileNotFoundException(\n                        description + \" cannot be resolved to absolute file path \" +\n                                \"because it does not reside in the file system\"\n                );\n            }\n            return getFile(url, description);\n        }\n        try {\n            // try URL\n            return getFile(new URL(resourceLocation));\n        } catch (MalformedURLException ex) {\n            // no URL -> treat as file path\n            return new File(resourceLocation);\n        }\n    }\n\n    /**\n     * Resolve the given resource URL to a {@code java.io.File},\n     * i.e. to a file in the file system.","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/perwendel/spark/blob/1973e402f5d4c1442ad34a1d38ed0758079f7773/src/main/java/spark/utils/ResourceUtils.java#L152-L188","documentation":"ResourceUtils.getFile(String) resolves a classpath-prefixed ('classpath:') location to an absolute java.io.File. It throws FileNotFoundException when the resource cannot be found on the classpath, and the message also covers the case where a resource exists only inside a jar/zip and therefore has no file-system path.","triggerScenarios":"Calling ResourceUtils.getFile(\"classpath:some/file.properties\") when the path is not on the classpath (typo, missing resource, wrong module), or when getResource returns a jar: URL instead of a file: URL because the resource is packaged in a jar.","commonSituations":"Forgetting to put a resource folder on the test classpath; renaming/moving a resource; expecting a classpath resource inside a fat jar to be readable as a File (it never is); resource excluded by build filters.","solutions":["Verify the path after 'classpath:' matches a file actually present on the runtime classpath (check target/classes or the jar contents).","If the resource lives inside a jar, read it as a stream (ClassUtils.getDefaultClassLoader().getResourceAsStream(path)) instead of a File.","Use ClassLoader.getResource(path) yourself first and inspect the URL protocol to confirm it is 'file'.","Fix build configuration so the resources directory is included on the classpath."],"exampleFix":"// before\nFile f = ResourceUtils.getFile(\"classpath:config/app.properties\");\n// after\nInputStream in = ClassUtils.getDefaultClassLoader().getResourceAsStream(\"config/app.properties\");\nif (in == null) throw new FileNotFoundException(\"config/app.properties not on classpath\");","handlingStrategy":"validation","validationCode":"String path = location.substring(\"classpath:\".length());\nif (ClassUtils.getDefaultClassLoader().getResource(path) == null)\n    throw new IllegalStateException(\"Resource not on classpath: \" + path);","typeGuard":null,"tryCatchPattern":"try {\n    File f = ResourceUtils.getFile(\"classpath:app.properties\");\n} catch (FileNotFoundException e) {\n    // fall back to stream access from the jar\n    try (InputStream in = getClass().getResourceAsStream(\"/app.properties\")) { ... }\n}","preventionTips":["Keep resources under src/main/resources so they land on the classpath automatically.","Never assume a classpath resource is a File when the app runs from a jar — prefer streams.","Verify packaged artifacts (jar tf app.jar) contain expected resource paths before release.","Check the URL protocol returned by getResource before converting to File."],"tags":["file-not-found","classpath","resources"],"backgroundTag":"file-not-found","analyzedSha":"1973e402f5d4c1442ad34a1d38ed0758079f7773","analyzedAt":"2026-09-10T14:38:22.866Z","contentChangedAt":"2026-09-10T14:38:22.866Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}