{"record":{"id":"a3ee852823c6fcf1","repo":"apache/flink","slug":"unexpected-object-type-for-timestamp-logical-type","errorCode":null,"errorMessage":"Unexpected object type for TIMESTAMP logical type. Received: {}","messagePattern":"Unexpected object type for TIMESTAMP 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":227,"sourceCode":"            }\n            return new GenericMapData(result);\n        };\n    }\n\n    private static TimestampData convertToTimestamp(Object object) {\n        final long millis;\n        if (object instanceof Long) {\n            millis = (Long) object;\n        } else if (object instanceof Instant) {\n            millis = ((Instant) object).toEpochMilli();\n        } else if (object instanceof LocalDateTime) {\n            return TimestampData.fromLocalDateTime((LocalDateTime) object);\n        } else {\n            JodaConverter jodaConverter = JodaConverter.getConverter();\n            if (jodaConverter != null) {\n                millis = jodaConverter.convertTimestamp(object);\n            } 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);","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/AvroToRowDataConverters.java#L209-L245","documentation":"convertToTimestamp accepts only Long (epoch millis), java.time.Instant, java.time.LocalDateTime, or Joda types (when JodaConverter is on the classpath). Any other Java object appearing where an Avro timestamp logical type is expected throws IllegalArgumentException with the received type's toString().","triggerScenarios":"The Avro data value for a timestamp field is a String, GenericFixed, Integer, or a custom class; e.g. a producer wrote timestamps as strings, or the writer schema declared no logical type so Avro decoded the field as something other than the expected Long/Instant.","commonSituations":"Writer/reader schema mismatch: field declared as timestamp-millis in the reader but plain long/string/fixed in the writer; heterogeneous producers; third-party Avro data with non-standard timestamp encodings.","solutions":["Compare writer and reader schemas for the timestamp field and align them so Avro decodes to Long/Instant.","If the source genuinely stores strings, read it as STRING and convert with a UDF/mapper instead of declaring it TIMESTAMP in the Avro mapping.","Verify Joda support if the data contains org.joda.time values: keep joda-time on the classpath so JodaConverter.getConverter() returns non-null."],"exampleFix":"// before\n// reader schema: {\"name\":\"ts\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}}\n// writer schema: {\"name\":\"ts\",\"type\":\"string\"} -> crashes\n\n// after\n// declare the field STRING in the table schema and convert:\nSELECT TO_TIMESTAMP_LTZ(CAST(ts AS BIGINT), 3) ... -- if producer writes epoch millis as text","handlingStrategy":"type-guard","validationCode":"Object v = record.get(fieldPos);\nboolean ok = v instanceof Long || v instanceof Instant || v instanceof LocalDateTime;\nif (!ok && JodaConverter.getConverter() == null) {\n    throw new IllegalArgumentException(\"Unconvertible timestamp value: \" + (v == null ? \"null\" : v.getClass()));\n}","typeGuard":"static boolean isAvroTimestampValue(Object v) {\n    return v instanceof Long || v instanceof Instant || v instanceof LocalDateTime\n            || (JodaConverter.getConverter() != null && JodaConverter.getConverter().convertsTimestamp(v));\n}","tryCatchPattern":null,"preventionTips":["Verify the writer schema marks timestamp fields with the timestamp-millis/micros logicalType.","Sample and type-check incoming records before full ingestion.","Keep joda-time on the classpath if producers emit Joda values."],"tags":["avro","flink","timestamp","schema-mismatch","logical-type"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}