{"record":{"id":"c7e69a6a57f36665","repo":"flowable/flowable-engine","slug":"couldn-t-read-input-stream-inputstreamname","errorCode":null,"errorMessage":"couldn't read input stream ${inputStreamName}","messagePattern":"couldn't read input stream (.+?)","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":45,"sourceCode":"\n/**\n * @author Tom Baeyens\n * @author Frederik Heremans\n * @author Joram Barrez\n */\npublic class IoUtil {\n\n    public static byte[] readInputStream(InputStream inputStream, String inputStreamName) {\n        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();\n        byte[] buffer = new byte[16 * 1024];\n        try {\n            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","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/util/IoUtil.java#L27-L63","documentation":"IoUtil.readInputStream copies an InputStream into a byte array and wraps any exception during reading into FlowableException with the stream's name, keeping the cause. The name parameter is purely for diagnostics.","triggerScenarios":"Reading a deployment resource or classpath stream that is closed, truncated, or whose underlying source fails mid-read (network stream drop, corrupted resource, closed auto-managed stream).","commonSituations":"Loading BPMN/dmn resources from a jar/URL where the stream was already consumed; temporary file deleted while reading; remote stream interrupted.","solutions":["Check the cause of the FlowableException for the underlying IO problem","Ensure the stream is open and not previously consumed before passing it to readInputStream","Verify the resource actually exists and is fully accessible (correct classpath/URL)","Increase robustness by re-opening the resource from a stable source instead of reusing streams"],"exampleFix":"// before\nInputStream is = getClass().getResourceAsStream(path);\nis.read(); // consumed earlier\nbyte[] bytes = IoUtil.readInputStream(is, path);\n// after\nInputStream is = getClass().getResourceAsStream(path);\nbyte[] bytes = IoUtil.readInputStream(is, path); // stream used exactly once","handlingStrategy":"try-catch","validationCode":"InputStream in = loader.getResourceAsStream(name);\nif (in == null) throw new IllegalStateException(\"Resource not on classpath: \" + name);","typeGuard":null,"tryCatchPattern":"try {\n    byte[] bytes = IoUtil.readInputStream(in, name);\n} catch (FlowableException e) {\n    logger.error(\"Failed reading stream {}: {}\", name, e.getCause(), e.getCause());\n}","preventionTips":["Never reuse an already-consumed InputStream","Keep a reference to the cause (e.getCause()) for diagnosis","Re-open resources from their source instead of caching streams"],"tags":["flowable","io","inputstream","resource-loading"],"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-18T11:17:12.947Z"}