{"record":{"id":"48d8904a3b4ba2c5","repo":"apache/iceberg","slug":"unexpected-object-type-for-timestamp-logical-type-48d890","errorCode":null,"errorMessage":"Unexpected object type for TIMESTAMP logical type. Received: ","messagePattern":"Unexpected object type for TIMESTAMP logical type\\. Received: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/formats/avro/AvroToRowDataConverters.java","lineNumber":251,"sourceCode":"        return TimestampData.fromEpochMillis(timeLong);\n      } else if (precision <= 6) {\n        return TimestampData.fromEpochMillis(\n            Math.floorDiv(timeLong, 1000L), (int) Math.floorMod(timeLong, 1000L) * 1000);\n      } else {\n        // Iceberg: Added support for nanoseconds precision (FLINK-39251)\n        return TimestampData.fromEpochMillis(\n            Math.floorDiv(timeLong, 1_000_000L), (int) Math.floorMod(timeLong, 1_000_000L));\n      }\n    } else if (object instanceof Instant) {\n      return TimestampData.fromInstant((Instant) object);\n    } else if (object instanceof LocalDateTime) {\n      return TimestampData.fromLocalDateTime((LocalDateTime) object);\n    } else {\n      JodaConverter jodaConverter = JodaConverter.getConverter();\n      if (jodaConverter != null) {\n        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      }","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/formats/avro/AvroToRowDataConverters.java#L233-L269","documentation":"convertToTimestamp throws IllegalArgumentException when the Avro reader produces an object for a TIMESTAMP logical type that is neither java.time.LocalDateTime nor a Joda-time convertible object (and no Joda converter is available).","triggerScenarios":"Avro datum is e.g. a java.util.Date, Long, or Instant while the converter expects LocalDateTime or a Joda class; Joda-Time not on classpath so legacy objects cannot be converted.","commonSituations":"Mixed Avro writer versions: newer writers emit java.time types, older writers emit Joda or millis-Long; missing joda-time dependency in the Flink job.","solutions":["Ensure the Avro reader returns java.time.LocalDateTime for timestamp fields (use a matching Avro datum reader version)","Add org.joda:joda-time to the classpath if reading data produced by old Avro writers","Normalize upstream Avro writing to the ISO/LocalDateTime encoding this converter expects"],"exampleFix":"// before\nObject object = record.get(\"ts\"); // java.util.Date — throws\n// after\nLocalDateTime object = ((Instant) record.get(\"ts\")).atZone(ZoneOffset.UTC).toLocalDateTime();","handlingStrategy":"type-guard","validationCode":"if (!(object instanceof LocalDateTime) && !isJodaDateTime(object)) { throw new IllegalArgumentException(\"Expected LocalDateTime for TIMESTAMP field, got \" + object.getClass()); }","typeGuard":"boolean isTimestampDatum(Object o) { return o instanceof LocalDateTime || o instanceof org.joda.time.LocalDateTime; }","tryCatchPattern":"try { return convertToTimestamp(object); } catch (IllegalArgumentException e) { throw new IllegalStateException(\"Avro writer produced unexpected timestamp encoding: \" + e.getMessage(), e); }","preventionTips":["Confirm joda-time is on the classpath if reading legacy Avro data","Pin Avro reader versions that emit java.time types","Test against real files from each producer version"],"tags":["flink","avro","timestamp","type-mismatch","joda"],"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"}