flowable/flowable-engine · error · FlowableIllegalArgumentException

Converter can only convert shorts

Error message

Converter can only convert shorts

What it means

ShortRestVariableConverter.getVariableValue converts an engine REST variable value back into a Short. If the raw value stored in EngineRestVariable is not a java.lang.Number, the converter cannot narrow it to a short and throws FlowableIllegalArgumentException. This is an internal type-invariant check protecting the REST variable type system.

Solutions

  1. Ensure the variable value is stored as a numeric type (Integer/Long/Short/BigDecimal) before REST conversion.
  2. Fix the client/serializer that is sending a non-numeric value for a short-typed variable.
  3. Verify the converter's getTypeName()/getVariableType mapping matches the actual variable type being converted.

Example fix

// before
result.setValue("42"); // string set for short variable
// after
result.setValue(42); // numeric value the short converter can handle
Defensive patterns

Strategy: type-guard

Validate before calling

if (result.getValue() != null && !(result.getValue() instanceof Number)) {
    throw new IllegalArgumentException("Expected numeric value for short variable, got: " + result.getValue().getClass());
}

Type guard

static boolean isNumeric(Object v) { return v instanceof Number; }

Try / catch

try {
    Object v = converter.getVariableValue(result);
} catch (FlowableIllegalArgumentException e) {
    // inspect result.getValue() type, log and fall back to default short
}

Prevention

When it happens

Trigger: Calling getVariableValue on an EngineRestVariable whose getValue() returns a non-Number object (e.g. a String or custom object) while this converter is registered as the handler for the 'short' REST variable type.

Common situations: A variable stored/passed with a mismatched type (string '5' instead of numeric 5), a custom converter chain or deserializer producing the wrong Java type, or someone registering ShortRestVariableConverter for the wrong variable type name.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

Thrown at modules/flowable-common-rest/src/main/java/org/flowable/common/rest/variable/ShortRestVariableConverter.java:37

 * @author Frederik Heremans
 */
public class ShortRestVariableConverter implements RestVariableConverter {

    @Override
    public String getRestTypeName() {
        return "short";
    }

    @Override
    public Class<?> getVariableType() {
        return Short.class;
    }

    @Override
    public Object getVariableValue(EngineRestVariable result) {
        if (result.getValue() != null) {
            if (!(result.getValue() instanceof Number)) {
                throw new FlowableIllegalArgumentException("Converter can only convert shorts");
            }
            return ((Number) result.getValue()).shortValue();
        }
        return null;
    }

    @Override
    public void convertVariableValue(Object variableValue, EngineRestVariable result) {
        if (variableValue != null) {
            if (!(variableValue instanceof Short)) {
                throw new FlowableIllegalArgumentException("Converter can only convert shorts");
            }
            result.setValue(variableValue);
        } else {
            result.setValue(null);
        }
    }

View on GitHub (pinned to d6d39ce1c6)