apache/flink · error · IllegalArgumentException
Unexpected object type for TIME logical type. Received: {}
Error message
Unexpected object type for TIME logical type. Received: {} What it means
convertToTime accepts only Integer (millis of day) or java.time.LocalTime (plus Joda when available). Any other object decoded for a TIME logical-type field throws IllegalArgumentException with the received value.
Source
Thrown at flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/AvroToRowDataConverters.java:261
} else {
throw new IllegalArgumentException(
"Unexpected object type for DATE logical type. Received: " + object);
}
}
}
private static int convertToTime(Object object) {
final int millis;
if (object instanceof Integer) {
millis = (Integer) object;
} else if (object instanceof LocalTime) {
millis = ((LocalTime) object).get(ChronoField.MILLI_OF_DAY);
} else {
JodaConverter jodaConverter = JodaConverter.getConverter();
if (jodaConverter != null) {
millis = jodaConverter.convertTime(object);
} else {
throw new IllegalArgumentException(
"Unexpected object type for TIME logical type. Received: " + object);
}
}
return millis;
}
private static byte[] convertToBytes(Object object) {
if (object instanceof GenericFixed) {
return ((GenericFixed) object).bytes();
} else if (object instanceof ByteBuffer) {
ByteBuffer byteBuffer = (ByteBuffer) object;
byte[] bytes = new byte[byteBuffer.remaining()];
byteBuffer.get(bytes);
return bytes;
} else {
return (byte[]) object;
}
}View on GitHub (pinned to 2f3c205e92)
Solutions
- Declare {"type":"int","logicalType":"time-millis"} in the writer schema and encode as int millis-of-day.
- Read string-encoded times as STRING and CAST to TIME in SQL.
- Pre-convert time values to millis-of-day before writing Avro.
Example fix
// before
// field encoded as "12:30:00" string, mapped to TIME(3)
// after
// writer schema: {"name":"t","type":{"type":"int","logicalType":"time-millis"}}
// or SQL: CAST(t AS TIME(3)) over a STRING column Defensive patterns
Strategy: type-guard
Validate before calling
Object v = record.get(fieldPos);
if (!(v instanceof Integer) && !(v instanceof LocalTime)
&& JodaConverter.getConverter() == null) {
throw new IllegalArgumentException("Unconvertible time value class: " + v.getClass());
} Type guard
static boolean isAvroTimeValue(Object v) {
return v instanceof Integer || v instanceof LocalTime;
} Prevention
- Encode times as int millis-of-day with the time-millis logicalType.
- Use SQL CAST for string-encoded times instead of the logical-type path.
When it happens
Trigger: Writer schema has no 'time-millis' logicalType on the int field (yielding a non-Integer decode path is rare, but strings/longs appear with mismatched schemas), or the producer encodes times as strings/longs.
Common situations: Time stored as 'HH:mm:ss' strings by another tool; schema evolution removing logical type annotations; precision mismatch producing Long where Integer expected.
Related errors
- Unexpected object type for TIMESTAMP logical type. Received:
- Unexpected object type for DATE logical type. Received: {}
- Failed to serialize schema registry.
- Avro does not support TIME type with precision: %s, it only
- Schema provided for '%s' format does not match the table sch
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/1f168d248c91ba7f.
Report an issue: GitHub.