{"record":{"id":"1b86d40786230a01","repo":"flowable/flowable-engine","slug":"couldn-t-read-file-filepath-e-getmessage","errorCode":null,"errorMessage":"Couldn't read file ${filePath}: ${e.getMessage()}","messagePattern":"Couldn't read 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":57,"sourceCode":"            int bytesRead = inputStream.read(buffer);\n            while (bytesRead != -1) {\n                outputStream.write(buffer, 0, bytesRead);\n                bytesRead = inputStream.read(buffer);\n            }\n        } catch (Exception e) {\n            throw new FlowableException(\"couldn't read input stream \" + inputStreamName, e);\n        }\n        return outputStream.toByteArray();\n    }\n\n    public static String readFileAsString(String filePath) {\n        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 {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/util/IoUtil.java#L39-L75","documentation":"IoUtil.readFileAsString reads a whole file into a String and wraps any exception in FlowableException 'Couldn't read file <path>: <message>'. Note it first calls getFile(path), so a file that cannot be located via the classloader fails earlier in getFile (error 1819).","triggerScenarios":"Calling IoUtil.readFileAsString for a path that resolves via classloader but cannot be opened/read: unreadable permissions, file removed between lookup and read, or IO error during read.","commonSituations":"Reading config/resource files bundled with the app; files inside jars/WARs where File-based access breaks; permission changes in containerized deployments.","solutions":["Check the embedded cause message for the concrete IO error","Verify the file exists on the filesystem (getFile resolves classloader resources — files inside jars are not plain Files)","Fix filesystem permissions on the file/directory","Prefer getResourceAsStream-based reading for classpath resources inside archives"],"exampleFix":"// before\nString content = IoUtil.readFileAsString(\"config/process.xml\");\n// after\ntry (InputStream in = getClass().getClassLoader().getResourceAsStream(\"config/process.xml\")) {\n    String content = IoUtil.readInputStream(in, \"config/process.xml\").toString();\n}","handlingStrategy":"try-catch","validationCode":"File f = new File(filePath);\nif (!f.isFile() || !f.canRead()) {\n    throw new IllegalStateException(\"Cannot read file: \" + filePath);\n}","typeGuard":null,"tryCatchPattern":"try {\n    String content = IoUtil.readFileAsString(filePath);\n} catch (FlowableException e) {\n    logger.error(\"File read failed for {}: {}\", filePath, e.getMessage());\n}","preventionTips":["Confirm the file is on the real filesystem, not inside a jar (use getResourceAsStream otherwise)","Check read permissions after deployments/container builds","Don't assume classpath-relative paths map to disk files"],"tags":["flowable","io","file-read","classpath"],"backgroundTag":"file-read-failed","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"}