{"record":{"id":"6e594b61a6ea3b7f","repo":"flowable/flowable-engine","slug":"couldn-t-get-file-filepath-e-getmessage-6e594b","errorCode":null,"errorMessage":"Couldn't get file ${filePath}: ${e.getMessage()}","messagePattern":"Couldn't get file (.+?): (.+?)","errorType":"exception","errorClass":"org.activiti.engine.ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/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 ActivitiException(\"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 ActivitiException(\"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 ActivitiException(\"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/flowable5-engine/src/main/java/org/activiti/engine/impl/util/IoUtil.java#L51-L87","documentation":"IoUtil.getFile resolves a classpath resource URL and converts it to a java.io.File via url.toURI(). Any failure — resource not found (URL null causing NPE), non-file URI schemes like jar:/bundle:, or URISyntaxException — becomes this ActivitiException with the path and cause message.","triggerScenarios":"Calling IoUtil.getFile (directly or via writeStringToFile/readFileAsString/buffer) with a path that isn't a classpath resource, or one packaged inside a jar where the 'jar:' URI cannot be converted to a File.","commonSituations":"Typo'd resource path; resource not on the classpath; attempting File access on resources inside a Spring Boot fat jar or OSGi bundle.","solutions":["Confirm the resource exists on the classpath at exactly that path (Class.getResource returns non-null).","Don't use getFile for resources inside jars — read via getResourceAsStream instead.","Null-check the URL before conversion and fail with a clearer 'resource not found' message.","Verify packaging: resources must be exploded directories for File-based access."],"exampleFix":"// before\nFile f = IoUtil.getFile(\"templates/app.vm\"); // inside a fat jar -> throws\n// after\ntry (InputStream in = IoUtil.class.getClassLoader().getResourceAsStream(\"templates/app.vm\")) {\n    // read stream instead of File\n}","handlingStrategy":"validation","validationCode":"URL url = IoUtil.class.getClassLoader().getResource(filePath);\nif (url == null) throw new IllegalStateException(\"Classpath resource not found: \" + filePath);\nif (!\"file\".equals(url.getProtocol())) throw new IllegalStateException(\"Resource inside jar, use getResourceAsStream: \" + url);","typeGuard":null,"tryCatchPattern":"try {\n    File f = IoUtil.getFile(path);\n} catch (ActivitiException e) {\n    if (e.getMessage().startsWith(\"Couldn't get file\")) { /* switch to stream-based loading */ }\n}","preventionTips":["Never use getFile for nested-jar/fat-jar resources — always stream them","Null-check getResource() result before any File conversion","Confirm exploded (directory) deployment if File-based access is required"],"tags":["io","classpath","file-not-found","jar"],"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-18T11:17:12.947Z"}