{"record":{"id":"b70e0e6349402e27","repo":"flowable/flowable-engine","slug":"could-not-get-byte-array-from-resource-resource-b70e0e","errorCode":null,"errorMessage":"could not get byte array from resource '${resourceName}'","messagePattern":"could not get byte array from resource '(.+?)'","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/repository/CmmnDeploymentBuilderImpl.java","lineNumber":59,"sourceCode":"\n    public CmmnDeploymentBuilderImpl() {\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration();\n        this.repositoryService = (CmmnRepositoryServiceImpl) cmmnEngineConfiguration.getCmmnRepositoryService();\n        this.deployment = cmmnEngineConfiguration.getCmmnDeploymentEntityManager().create();\n        this.resourceEntityManager = cmmnEngineConfiguration.getCmmnResourceEntityManager();\n    }\n\n    @Override\n    public CmmnDeploymentBuilder addInputStream(String resourceName, InputStream inputStream) {\n        if (inputStream == null) {\n            throw new FlowableException(\"inputStream for resource '\" + resourceName + \"' is null\");\n        }\n\n        byte[] bytes = null;\n        try {\n            bytes = IoUtil.readInputStream(inputStream, resourceName);\n        } catch (Exception e) {\n            throw new FlowableException(\"could not get byte array from resource '\" + resourceName + \"'\", e);\n        }\n\n        if (bytes == null) {\n            throw new FlowableException(\"byte array for resource '\" + resourceName + \"' is null\");\n        }\n\n        CmmnResourceEntity resource = resourceEntityManager.create();\n        resource.setName(resourceName);\n        resource.setBytes(bytes);\n        deployment.addResource(resource);\n        return this;\n    }\n\n    @Override\n    public CmmnDeploymentBuilder addClasspathResource(String resource) {\n        try (final InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(resource)) {\n            if (inputStream == null) {\n                throw new FlowableException(\"resource '\" + resource + \"' not found\");","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/repository/CmmnDeploymentBuilderImpl.java#L41-L77","documentation":"CmmnDeploymentBuilderImpl.addInputStream throws FlowableException with \"could not get byte array from resource '<resourceName>'\" when IoUtil.readInputStream fails while reading the provided stream. The original exception is preserved as the cause; this usually means the stream is unreadable, already closed, or I/O fails mid-read.","triggerScenarios":"Passing an InputStream that was already consumed/closed, a stream backed by a deleted file, or any stream whose read() throws IOException during deployment resource registration.","commonSituations":"Reusing a stream that was read earlier in the same deployment; try-with-resources closing the stream before the builder reads it; network/socket-backed streams interrupted mid-read.","solutions":["Ensure a fresh, open InputStream is passed for each resource — never reuse a consumed or closed stream.","Inspect the wrapped cause (e.getCause()) for the real I/O error and fix that (file permissions, missing file, network).","Read the bytes yourself first (verify length > 0) and then hand a ByteArrayInputStream to addInputStream if you need controlled behavior."],"exampleFix":"// before\nInputStream is = Files.newInputStream(path);\nis.close();\nbuilder.addInputStream(name, is); // read fails: stream closed\n\n// after\nbyte[] bytes = Files.readAllBytes(path);\nbuilder.addInputStream(name, new ByteArrayInputStream(bytes));","handlingStrategy":"try-catch","validationCode":"byte[] bytes = Files.readAllBytes(path); // fails early if unreadable\nbuilder.addInputStream(name, new ByteArrayInputStream(bytes));","typeGuard":null,"tryCatchPattern":"try {\n    builder.addInputStream(name, is);\n} catch (FlowableException e) {\n    if (e.getCause() == null || !e.getMessage().contains(\"could not get byte array\")) throw e;\n    logger.error(\"failed reading resource \" + name, e.getCause());\n    throw new DeploymentException(\"unreadable resource: \" + name, e.getCause());\n}","preventionTips":["Never reuse or pre-close InputStreams handed to the builder","Inspect e.getCause() to diagnose the underlying I/O failure","Read files fully into memory before deployment when possible"],"tags":["io","stream","deployment","cmmn"],"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-14T16:17:12.679Z"}