flowable/flowable-engine · error · IllegalStateException

Cannot initialize byte array. There is no command context an

Error message

Cannot initialize byte array. There is no command context and there is no command Executor

What it means

ByteArrayRef lazily loads its byte array entity, which requires either an active CommandContext or a configured CommandExecutor. ensureInitialized throws IllegalStateException when both are absent, since there is no way to run the database lookup for the referenced byte array.

Source

Thrown at modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/persistence/entity/ByteArrayRef.java:148

                getEngineConfiguration(engineType).getByteArrayEntityManager().delete(entity);
            } else {
                getEngineConfiguration(engineType).getByteArrayEntityManager().deleteByteArrayById(id);
            }
            entity = null;
            id = null;
            deleted = true;
        }
    }

    protected void ensureInitialized(String engineType) {
        if (id != null && entity == null) {
            CommandContext commandContext = Context.getCommandContext();
            if (commandContext != null) {
                entity = getEngineConfiguration(engineType).getByteArrayEntityManager().findById(id);
            } else if (commandExecutor != null) {
                entity = commandExecutor.execute(context -> getEngineConfiguration(engineType).getByteArrayEntityManager().findById(id));
            } else {
                throw new IllegalStateException("Cannot initialize byte array. There is no command context and there is no command Executor");
            }

            if (entity != null) {
                name = entity.getName();
            }
        }
    }

    public boolean isDeleted() {
        return deleted;
    }

    /**
     * This makes a copy of this {@link ByteArrayRef}: a new
     * {@link ByteArrayRef} instance will be created, however with the same id,
     * name and {@link ByteArrayEntity} instances.
     */
    public ByteArrayRef copy() {

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Access the byte content inside a command, e.g. managementService.executeCommand(commandContext -> byteArrayRef.getBytes())
  2. Keep the entity/content access within the same command/transaction where the engine is active
  3. If running standalone, configure the ByteArrayRef's commandExecutor before use

Example fix

// before
byte[] data = byteArrayRef.getBytes(); // outside command context
// after
byte[] data = managementService.executeCommand(ctx -> byteArrayRef.getBytes());
Defensive patterns

Strategy: try-catch

Validate before calling

boolean safeToRead = org.flowable.common.engine.impl.context.Context.getCommandContext() != null;

Try / catch

try {
    byte[] data = ref.getBytes();
} catch (IllegalStateException e) {
    if (e.getMessage().startsWith("Cannot initialize byte array")) {
        // re-run inside executeCommand
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling getBytes()/setBytes()/getEntity() on a ByteArrayRef outside of a command (e.g. in a plain thread, after the engine closed, or in a standalone app) when neither Context.getCommandContext() nor a commandExecutor is available.

Common situations: Reading content (e.g. an attachment or variable of type bytes) after the command/transaction ended; using engine entities in custom code without running inside a ProcessEngine command or setting a commandExecutor; unit tests without a command context.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/16de64d6bec5cb7a. Report an issue: GitHub.