{"record":{"id":"2994c045b2e07c38","repo":"flowable/flowable-engine","slug":"could-not-get-byte-array-from-resource-resource-2994c0","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-event-registry/src/main/java/org/flowable/eventregistry/impl/repository/EventDeploymentBuilderImpl.java","lineNumber":61,"sourceCode":"\n    public EventDeploymentBuilderImpl() {\n        EventRegistryEngineConfiguration eventRegistryEngineConfiguration = CommandContextUtil.getEventRegistryConfiguration();\n        this.repositoryService = (EventRepositoryServiceImpl) eventRegistryEngineConfiguration.getEventRepositoryService();\n        this.deployment = eventRegistryEngineConfiguration.getDeploymentEntityManager().create();\n        this.resourceEntityManager = eventRegistryEngineConfiguration.getResourceEntityManager();\n    }\n\n    @Override\n    public EventDeploymentBuilder 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 = IOUtils.toByteArray(inputStream);\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        EventResourceEntity resource = resourceEntityManager.create();\n        resource.setName(resourceName);\n        resource.setBytes(bytes);\n        deployment.addResource(resource);\n        return this;\n    }\n\n    @Override\n    public EventDeploymentBuilder 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":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-event-registry/src/main/java/org/flowable/eventregistry/impl/repository/EventDeploymentBuilderImpl.java#L43-L79","documentation":"After reading the supplied InputStream with IOUtils.toByteArray, EventDeploymentBuilderImpl.addInputStream wraps any read failure in this FlowableException, preserving the original exception as the cause. It signals that the resource bytes could not be extracted from the stream.","triggerScenarios":"addInputStream is called with a stream whose read() throws — e.g. a closed stream, a broken file handle, an IO error while reading a network-backed stream — so IOUtils.toByteArray throws inside the try block.","commonSituations":"Passing an already-consumed or closed InputStream (stream read twice); reading from a temp file deleted mid-deployment; container classloader stream errors; disk/socket IO failures when the resource is remote.","solutions":["Inspect the cause exception attached to this FlowableException to identify the underlying IO problem","Pass a freshly opened InputStream (do not reuse a consumed/closed stream) for each deployment","If reading a file, verify it exists, is readable, and open it immediately before addInputStream"],"exampleFix":"// before\nbyte[] unused = IOUtils.toByteArray(is); // consumes stream\nis.close();\ndeploymentBuilder.addInputStream(name, is); // already closed\n// after\ndeploymentBuilder.addInputStream(name, new FileInputStream(file)); // fresh stream","handlingStrategy":"try-catch","validationCode":"// can be caught; ensure stream is fresh and readable before deploy\ntry (InputStream is = new FileInputStream(file)) {\n    if (is.read() == -1) throw new IllegalStateException(\"empty resource: \" + file);\n}","typeGuard":null,"tryCatchPattern":"try {\n    deploymentBuilder.addInputStream(name, stream);\n} catch (FlowableException e) {\n    if (e.getMessage().contains(\"could not get byte array\")) {\n        // inspect e.getCause() for the underlying IOException and reopen the stream\n    } else { throw e; }\n}","preventionTips":["Do not reuse or pre-close streams before addInputStream","Check e.getCause() to diagnose the real IO failure","Read resources from stable local storage, not volatile temp paths"],"tags":["flowable","deployment","io"],"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"}