{"record":{"id":"ad641128ef970648","repo":"flowable/flowable-engine","slug":"converter-can-only-convert-localdate","errorCode":null,"errorMessage":"Converter can only convert localDate","messagePattern":"Converter can only convert localDate","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/flowable-common-rest/src/main/java/org/flowable/common/rest/variable/LocalDateRestVariableConverter.java","lineNumber":54,"sourceCode":"    public Object getVariableValue(EngineRestVariable result) {\n        if (result.getValue() != null) {\n            if (!(result.getValue() instanceof String)) {\n                throw new FlowableIllegalArgumentException(\"Converter can only convert string to localDate\");\n            }\n            try {\n                return LocalDate.parse((String) result.getValue());\n            } catch (DateTimeParseException e) {\n                throw new FlowableIllegalArgumentException(\"The given variable value is not a localDate: '\" + result.getValue() + \"'\", e);\n            }\n        }\n        return null;\n    }\n\n    @Override\n    public void convertVariableValue(Object variableValue, EngineRestVariable result) {\n        if (variableValue != null) {\n            if (!(variableValue instanceof LocalDate)) {\n                throw new FlowableIllegalArgumentException(\"Converter can only convert localDate\");\n            }\n            result.setValue(variableValue.toString());\n        } else {\n            result.setValue(null);\n        }\n    }\n\n}\n","sourceCodeStart":36,"sourceCodeEnd":63,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-common-rest/src/main/java/org/flowable/common/rest/variable/LocalDateRestVariableConverter.java#L36-L63","documentation":"LocalDateRestVariableConverter.convertVariableValue serializes an engine variable into a REST variable and requires the underlying value to be a java.time.LocalDate. Any other non-null object fails the instanceof check and throws FlowableIllegalArgumentException, since only LocalDate values can be rendered as localDate REST variables.","triggerScenarios":"Calling convertVariableValue(value, result) with a non-null object that is not a LocalDate (e.g. java.util.Date, String, LocalDateTime, ZonedDateTime), typically when serializing process/engine variables for REST responses where the variable type was declared localDate.","commonSituations":"Storing legacy java.util.Date variables but labeling them localDate in REST; a migration from Date to java.time leaving old variable instances; passing Strings that were never parsed into LocalDate.","solutions":["Convert the value to java.time.LocalDate (e.g. via Instant.atZone(...).toLocalDate() for Date) before serialization.","Declare/return the correct REST variable type for the actual Java type (e.g. use the Date converter for java.util.Date).","Migrate persisted variables of legacy types to LocalDate where possible.","Parse String values with LocalDate.parse before handing them to the converter."],"exampleFix":"// before\nconverter.convertVariableValue(new java.util.Date(), restVar); // throws\n\n// after\nLocalDate d = new java.util.Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();\nconverter.convertVariableValue(d, restVar);","handlingStrategy":"type-guard","validationCode":"if (value instanceof LocalDate) {\n    converter.convertVariableValue(value, restVar);\n} else if (value instanceof java.util.Date d) {\n    converter.convertVariableValue(LocalDate.ofInstant(d.toInstant(), ZoneId.systemDefault()), restVar);\n} else {\n    throw new IllegalArgumentException(\"Cannot serialize as localDate: \" + value.getClass());\n}","typeGuard":"static boolean isLocalDate(Object v) {\n    return v instanceof java.time.LocalDate;\n}","tryCatchPattern":"try {\n    converter.convertVariableValue(value, restVar);\n} catch (FlowableIllegalArgumentException e) {\n    throw new IllegalStateException(\"localDate REST variable requires java.time.LocalDate, got: \"\n        + value.getClass().getName(), e);\n}","preventionTips":["Standardize on java.time types in process variables; avoid java.util.Date.","Match the REST variable type declaration to the actual Java type.","Add converter round-trip tests for every variable type you expose."],"tags":["localdate","rest-variable","type-mismatch","date"],"backgroundTag":"type-mismatch","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}