apache/seatunnel · error · IllegalArgumentException
Cannot convert to long:
Error message
Cannot convert to long:
What it means
A generic type-guard in RowConverter.convertLong, hit when converting an Iceberg field value to a long. The method only supports values that are Number or String; any other runtime type (e.g. Boolean, java.util.Date, or an unexpected object) falls through the instanceof checks and this sentinel IllegalArgumentException is thrown, naming the offending value's class. It is raised via convertValue, meaning an incoming record contained a field whose runtime type is incompatible with the long conversion path.
Source
Thrown at seatunnel-connectors-v2/connector-iceberg/src/main/java/org/apache/seatunnel/connectors/seatunnel/iceberg/data/RowConverter.java:296
return result;
}
protected int convertInt(Object value) {
if (value instanceof Number) {
return ((Number) value).intValue();
} else if (value instanceof String) {
return Integer.parseInt((String) value);
}
throw new IllegalArgumentException("Cannot convert to int: " + value.getClass().getName());
}
protected long convertLong(Object value) {
if (value instanceof Number) {
return ((Number) value).longValue();
} else if (value instanceof String) {
return Long.parseLong((String) value);
}
throw new IllegalArgumentException("Cannot convert to long: " + value.getClass().getName());
}
protected float convertFloat(Object value) {
if (value instanceof Number) {
return ((Number) value).floatValue();
} else if (value instanceof String) {
return Float.parseFloat((String) value);
}
throw new IllegalArgumentException(
"Cannot convert to float: " + value.getClass().getName());
}
protected double convertDouble(Object value) {
if (value instanceof Number) {
return ((Number) value).doubleValue();
} else if (value instanceof String) {
return Double.parseDouble((String) value);
}View on GitHub (pinned to cf67b549a7)
Solutions
- Ensure the field value is numeric or numeric-string (convert Dates to epoch millis manually).
- Pre-cast in a transform: CAST(col AS BIGINT).
- Change the Iceberg column type (e.g. to TIMESTAMP) to match real data.
- Catch IllegalArgumentException for bad-record handling.
Example fix
// before row.setField(0, new Date()); // bigint field // after row.setField(0, date.getTime());
Defensive patterns
Strategy: type-guard
Validate before calling
if (!(v instanceof Number) && !(v instanceof String)) { throw new IllegalArgumentException("long field expects Number/String, got " + v.getClass()); } Type guard
Long safeToLong(Object v) { if (v instanceof Number) return ((Number) v).longValue(); if (v instanceof String) return Long.valueOf((String) v); if (v instanceof Date) return ((Date) v).getTime(); return null; } Try / catch
try { value = convertLong(raw); } catch (IllegalArgumentException e) { log.warn("Bad long value: {}", e.getMessage()); } Prevention
- Convert temporal types to epoch millis before sink
- Use transform CAST to BIGINT
- Align source and Iceberg column types
When it happens
Trigger: Writing to an Iceberg LongType field via convertValue when the value is, e.g., a Boolean, byte[], or temporal object.
Common situations: Timestamps represented as java.util.Date instead of epoch millis, booleans in BIGINT columns, JSON parsers emitting unexpected types.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Cannot convert to int:
- Cannot convert to float:
- Cannot convert to double:
- Cannot convert to struct:
- Cannot convert to BigDecimal:
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/fd098b6ea9d6777b.
Report an issue: GitHub.