flowable/flowable-engine · error · ActivitiException

Illegal argument exception when getting value from id method

Error message

Illegal argument exception when getting value from id method/field on JPAEntity

What it means

getIdValue reads the entity's primary key by reflectively invoking the @Id-annotated getter or accessing the @Id field. If the reflective call throws IllegalArgumentException (e.g. wrong receiver object for the Method/Field), it is wrapped in this ActivitiException.

Source

Thrown at modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityMappings.java:100

    public String getJPAIdString(Object value) {
        EntityMetaData metaData = getEntityMetaData(value.getClass());
        if (!metaData.isJPAEntity()) {
            throw new ActivitiIllegalArgumentException("Object is not a JPA Entity: class='" + value.getClass() + "', " + value);
        }
        Object idValue = getIdValue(value, metaData);
        return getIdString(idValue);
    }

    public Object getIdValue(Object value, EntityMetaData metaData) {
        try {
            if (metaData.getIdMethod() != null) {
                return metaData.getIdMethod().invoke(value);
            } else if (metaData.getIdField() != null) {
                return metaData.getIdField().get(value);
            }
        } catch (IllegalArgumentException iae) {
            throw new ActivitiException("Illegal argument exception when getting value from id method/field on JPAEntity", iae);
        } catch (IllegalAccessException iae) {
            throw new ActivitiException("Cannot access id method/field for JPA Entity", iae);
        } catch (InvocationTargetException ite) {
            throw new ActivitiException("Exception occurred while getting value from id field/method on JPAEntity: " +
                    ite.getCause().getMessage(), ite.getCause());
        }

        // Fall trough when no method and field is set
        throw new ActivitiException("Cannot get id from JPA Entity, no id method/field set");
    }

    public Object getJPAEntity(String className, String idString) {
        Class<?> entityClass = null;
        entityClass = ReflectUtil.loadClass(className);

        EntityMetaData metaData = getEntityMetaData(entityClass);
        if (metaData == null) {
            throw new ActivitiIllegalArgumentException("Class is not a JPA-entity: " + className);

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Redeploy cleanly so cached EntityMetaData matches the current classloader
  2. Ensure the object passed is an instance of the exact entity class the metadata was built from
  3. Check for duplicate entity classes on the classpath (two jars with the same FQCN)
Defensive patterns

Strategy: try-catch

Validate before calling

if (!metaClass.isInstance(value)) {
    throw new IllegalArgumentException("value is not an instance of " + metaClass.getName());
}

Type guard

boolean matchesMetadata(Class<?> metaClass, Object v) {
    return v != null && metaClass.isInstance(v);
}

Try / catch

try {
    Object id = mappings.getJPAIdString(entity);
} catch (ActivitiException e) {
    if (e.getMessage().contains("Illegal argument exception when getting value from id")) {
        // classloader/metadata mismatch — redeploy or rebuild metadata
    } else { throw e; }
}

Prevention

When it happens

Trigger: Invoking getIdValue with a value object that is not an instance of the class the id Method/Field belongs to — typically a classloader mismatch (same class name loaded by two loaders) or a mismatched EntityMetaData cache entry.

Common situations: Hot redeployment in an app server leaving stale EntityMetaData pointing at an old classloader's Method/Field; passing a proxy that is not an instance of the entity class.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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