{"record":{"id":"52c855828602633a","repo":"apache/iceberg","slug":"unexpected-object-type-for-date-logical-type-rece-52c855","errorCode":null,"errorMessage":"Unexpected object type for DATE logical type. Received: ${object}","messagePattern":"Unexpected object type for DATE logical type\\. Received: (.+?)","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/formats/avro/AvroToRowDataConverters.java","lineNumber":267,"sourceCode":"        return TimestampData.fromEpochMillis(jodaConverter.convertTimestamp(object));\n      } else {\n        throw new IllegalArgumentException(\n            \"Unexpected object type for TIMESTAMP logical type. Received: \" + object);\n      }\n    }\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":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/formats/avro/AvroToRowDataConverters.java#L249-L285","documentation":"Thrown by AvroToRowDataConverters.convertToDate when an Avro 'date' logical type field produces an object that is neither java.time.LocalDate nor a Joda-convertible type. It cannot be turned into an epoch-day int for Flink's DateType, so the converter throws with the object class/value in the message.","triggerScenarios":"Reading Avro data where a date field materializes as java.util.Date, String, or Integer instead of LocalDate, and JodaConverter is unavailable (no joda-time on classpath) or also cannot convert the type.","commonSituations":"Avro files written with reflect/generic records mapping 'date' to a non-LocalDate type; mixing java.time and Joda conventions across writer/reader versions.","solutions":["Ensure the Avro reader maps the 'date' logical type to java.time.LocalDate (use Conversions or an up-to-date specific record)","Add joda-time to the classpath if the source data uses legacy Joda date objects","Pre-convert the field to LocalDate before feeding the record into the Flink Avro reader","Align reader/writer schemas so the date logical type is declared in the schema"],"exampleFix":"// before: date field deserialized as String\n// after: normalize before conversion\nLocalDate d = LocalDate.parse((String) obj);","handlingStrategy":"type-guard","validationCode":"Object d = record.get(\"date\");\nif (!(d instanceof LocalDate)) {\n  d = LocalDate.parse(d.toString());\n  record.put(\"date\", d);\n}","typeGuard":"boolean isLocalDate(Object o) {\n  return o instanceof LocalDate;\n}","tryCatchPattern":"try {\n  RowData row = converter.convert(record);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"Unexpected object type for DATE\")) {\n    // convert field manually and retry\n  } else { throw e; }\n}","preventionTips":["Declare the 'date' logical type in the Avro schema","Ensure reader frameworks map date to java.time.LocalDate","Add joda-time for legacy data sources","Spot-check deserialized record field types in tests"],"tags":["flink","avro","date","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}