{"record":{"id":"b2aa38ab63a11a5b","repo":"flowable/flowable-engine","slug":"variable-type-must-be-byte-or-string","errorCode":null,"errorMessage":"Variable type must be byte[] or string","messagePattern":"Variable type must be byte\\[\\] or string","errorType":"exception","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/el/function/VariableBase64ExpressionFunction.java","lineNumber":39,"sourceCode":" * @author Joram Barrez\n */\npublic class VariableBase64ExpressionFunction extends AbstractFlowableVariableExpressionFunction {\n    \n    public VariableBase64ExpressionFunction() {\n        super(\"base64\");\n    }\n    \n    public static Object base64(VariableContainer variableContainer, String variableName) {\n        Object value = getVariableValue(variableContainer, variableName);\n\n        if (value == null) {\n            return null;\n        } else if (value instanceof Byte[] || value instanceof byte[]) {\n            return java.util.Base64.getEncoder().encodeToString( (byte[]) value);\n        } else if (value instanceof String) {\n            return java.util.Base64.getEncoder().encodeToString(((String) value).getBytes());\n        } else {\n            throw new FlowableIllegalArgumentException(\"Variable type must be byte[] or string\");\n        }\n    }\n\n}\n","sourceCodeStart":21,"sourceCodeEnd":44,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/el/function/VariableBase64ExpressionFunction.java#L21-L44","documentation":"VariableBase64ExpressionFunction.base64 (EL function vars:base64) converts a variable to a Base64 string, but only Byte[]/byte[] and String values are supported. Any other variable type (Integer, Serializable bean, List, etc.) cannot be encoded, so a FlowableIllegalArgumentException is thrown.","triggerScenarios":"Evaluating ${vars:base64(myVar)} where myVar is of a type other than byte[], Byte[], or String — e.g. an Integer, a POJO, a JSON node, or a Date.","commonSituations":"Misremembering which types the base64 function accepts; passing a numeric or object variable expecting implicit conversion to bytes/string; version differences where a variable's type changed (e.g. stored as String previously, now a POJO).","solutions":["Convert the variable to a String or byte[] before encoding, e.g. ${vars:base64(myVar.toString())} or serialize the object first in a delegate.","Pass a String variable directly if the content is textual.","Update the variable mapping (script/delegate) to produce byte[] or String for the target variable.","If encoding arbitrary objects is needed, implement custom serialization in a service task instead of the EL function."],"exampleFix":"// before\n${vars:base64(orderId)}   // orderId is Integer -> throws\n\n// after\n${vars:base64(orderId.toString())}","handlingStrategy":"type-guard","validationCode":"Object v = execution.getVariable(\"myVar\");\nif (v != null && !(v instanceof byte[]) && !(v instanceof Byte[]) && !(v instanceof String)) {\n    throw new IllegalArgumentException(\"vars:base64 requires byte[]/Byte[]/String, got \" + v.getClass());\n}","typeGuard":"boolean base64Encodable(Object v) {\n    return v == null || v instanceof String || v instanceof byte[] || v instanceof Byte[];\n}","tryCatchPattern":"try {\n    Object encoded = expressionManager.evaluateExpression(base64Expr, execution);\n} catch (FlowableIllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"byte[] or string\")) {\n        // fall back to serializing the object to String first\n    }\n    throw e;\n}","preventionTips":["Map variables to String or byte[] before applying vars:base64.","Document the accepted types where the expression is used in process definitions.","Add process-definition validation for expressions applying vars:base64 to non-string variables."],"tags":["el","function","base64","type-mismatch"],"backgroundTag":"incompatible-source-type","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"}