{"record":{"id":"5da48ebf3a81a172","repo":"apache/flink","slug":"unexpected-object-type-for-date-logical-type-rece","errorCode":null,"errorMessage":"Unexpected object type for DATE logical type. Received: {}","messagePattern":"Unexpected object type for DATE logical type\\. Received: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/AvroToRowDataConverters.java","lineNumber":244,"sourceCode":"            } else {\n                throw new IllegalArgumentException(\n                        \"Unexpected object type for TIMESTAMP logical type. Received: \" + object);\n            }\n        }\n        return TimestampData.fromEpochMillis(millis);\n    }\n\n    private static int convertToDate(Object object) {\n        if (object instanceof Integer) {\n            return (Integer) object;\n        } else if (object instanceof LocalDate) {\n            return (int) ((LocalDate) object).toEpochDay();\n        } else {\n            JodaConverter jodaConverter = JodaConverter.getConverter();\n            if (jodaConverter != null) {\n                return (int) jodaConverter.convertDate(object);\n            } else {\n                throw new IllegalArgumentException(\n                        \"Unexpected object type for DATE logical type. Received: \" + object);\n            }\n        }\n    }\n\n    private static int convertToTime(Object object) {\n        final int millis;\n        if (object instanceof Integer) {\n            millis = (Integer) object;\n        } else if (object instanceof LocalTime) {\n            millis = ((LocalTime) object).get(ChronoField.MILLI_OF_DAY);\n        } else {\n            JodaConverter jodaConverter = JodaConverter.getConverter();\n            if (jodaConverter != null) {\n                millis = jodaConverter.convertTime(object);\n            } else {\n                throw new IllegalArgumentException(\n                        \"Unexpected object type for TIME logical type. Received: \" + object);","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/AvroToRowDataConverters.java#L226-L262","documentation":"convertToDate accepts only Integer (days since epoch) or java.time.LocalDate (plus Joda types when joda-time is present). Any other object decoded for a DATE logical-type field throws IllegalArgumentException naming the received value.","triggerScenarios":"The Avro value for a date field is a String ('2024-01-01'), Long, or other type — typically because the writer schema lacks the 'date' logicalType (so Avro yields a plain value) or stores dates as strings.","commonSituations":"Producer wrote date fields as ISO strings; schema evolution stripped logical type annotations; avro-tools generated schemas without logicalTypes for legacy data.","solutions":["Ensure the writer schema declares {\"type\":\"int\",\"logicalType\":\"date\"} and data was encoded as int days-since-epoch.","If data is textual, map the column as STRING/DATE via CAST in SQL instead of relying on the Avro logical type.","Convert string dates to epoch-days before writing them as Avro."],"exampleFix":"// before\n// writer: {\"name\":\"d\",\"type\":\"string\"} + reader expects DATE -> crash\n\n// after\n// writer: {\"name\":\"d\",\"type\":{\"type\":\"int\",\"logicalType\":\"date\"}}\n// or in SQL: CAST(d AS DATE) from a STRING column","handlingStrategy":"type-guard","validationCode":"Object v = record.get(fieldPos);\nif (!(v instanceof Integer) && !(v instanceof LocalDate)\n        && JodaConverter.getConverter() == null) {\n    throw new IllegalArgumentException(\"Unconvertible date value class: \" + v.getClass());\n}","typeGuard":"static boolean isAvroDateValue(Object v) {\n    return v instanceof Integer || v instanceof LocalDate;\n}","tryCatchPattern":null,"preventionTips":["Ensure writer schemas use {\"type\":\"int\",\"logicalType\":\"date\"}.","Reject/normalize string-encoded dates at the producer."],"tags":["avro","flink","date","logical-type","schema-mismatch"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}