{"record":{"id":"630e20ea1dcf1bf4","repo":"flowable/flowable-engine","slug":"couldn-t-get-file-filepath-e-getmessage","errorCode":null,"errorMessage":"Couldn't get file ${filePath}: ${e.getMessage()}","messagePattern":"Couldn't get file (.+?): (.+?)","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/util/IoUtil.java","lineNumber":69,"sourceCode":"        byte[] buffer = new byte[(int) getFile(filePath).length()];\n        BufferedInputStream inputStream = null;\n        try {\n            inputStream = new BufferedInputStream(new FileInputStream(getFile(filePath)));\n            inputStream.read(buffer);\n        } catch (Exception e) {\n            throw new FlowableException(\"Couldn't read file \" + filePath + \": \" + e.getMessage());\n        } finally {\n            IoUtil.closeSilently(inputStream);\n        }\n        return new String(buffer);\n    }\n\n    public static File getFile(String filePath) {\n        URL url = IoUtil.class.getClassLoader().getResource(filePath);\n        try {\n            return new File(url.toURI());\n        } catch (Exception e) {\n            throw new FlowableException(\"Couldn't get file \" + filePath + \": \" + e.getMessage());\n        }\n    }\n\n    public static void writeStringToFile(String content, String filePath) {\n        BufferedOutputStream outputStream = null;\n        try {\n            outputStream = new BufferedOutputStream(new FileOutputStream(getFile(filePath)));\n            outputStream.write(content.getBytes());\n            outputStream.flush();\n        } catch (Exception e) {\n            throw new FlowableException(\"Couldn't write file \" + filePath, e);\n        } finally {\n            IoUtil.closeSilently(outputStream);\n        }\n    }\n\n    /**\n     * Closes the given stream. The same as calling {@link InputStream#close()}, but errors while closing are silently ignored.","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/util/IoUtil.java#L51-L87","documentation":"IoUtil.getFile resolves a path through the classloader (ClassLoader.getResource) and converts the URL to a File. Any failure — including a null URL when the resource is missing — is wrapped in FlowableException 'Couldn't get file <path>: <message>'.","triggerScenarios":"Calling getFile (directly or via readFileAsString/writeStringToFile) with a path that does not exist on the classpath, or a resource inside a jar (URL scheme like jar:file:... that File(...) cannot convert, e.g. URISyntaxException).","commonSituations":"Typo'd resource path; resource not included in the built artifact (missing from src/main/resources); attempting to access resources inside nested jars in Spring Boot fat jars; running from a packaged WAR.","solutions":["Verify the resource path exists and is on the classpath (check the built jar/war contents)","Fix typos and ensure the file is under src/main/resources so it is packaged","For resources inside jars, stream them with getResourceAsStream instead of converting to File","Call getFile only for resources that unpack to real filesystem files"],"exampleFix":"// before\nFile f = IoUtil.getFile(\"processes/order.bpmn20.xml\");\n// after\ntry (InputStream in = getClass().getClassLoader().getResourceAsStream(\"processes/order.bpmn20.xml\")) {\n    if (in == null) throw new IllegalStateException(\"resource missing from classpath\");\n    byte[] bytes = IoUtil.readInputStream(in, \"processes/order.bpmn20.xml\");\n}","handlingStrategy":"try-catch","validationCode":"if (getClass().getClassLoader().getResource(filePath) == null) {\n    throw new IllegalStateException(\"Resource not found on classpath: \" + filePath);\n}","typeGuard":null,"tryCatchPattern":"try {\n    File f = IoUtil.getFile(filePath);\n} catch (FlowableException e) {\n    logger.error(\"Resource lookup failed for {}: {}\", filePath, e.getMessage());\n}","preventionTips":["Verify resources are packaged (list jar contents after build)","For nested-jar resources (Spring Boot fat jar), use getResourceAsStream, not getFile","Double-check resource path spelling and directory placement in src/main/resources"],"tags":["flowable","io","classpath","resource-not-found","file"],"backgroundTag":"file-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}