apache/seatunnel · error · IllegalArgumentException

Cannot convert to int:

Error message

Cannot convert to int: 

What it means

convertInt accepts only Number and String values; any other Java type (Boolean, byte[], BigDecimal-in-some-flows, Date, etc.) cannot be converted to an Iceberg int and IllegalArgumentException with the value's class name is thrown.

Source

Thrown at seatunnel-connectors-v2/connector-iceberg/src/main/java/org/apache/seatunnel/connectors/seatunnel/iceberg/data/RowConverter.java:287

        Map<Object, Object> result = Maps.newHashMap();
        map.forEach(
                (k, v) -> {
                    int keyFieldId = type.fields().get(0).fieldId();
                    int valueFieldId = type.fields().get(1).fieldId();
                    result.put(
                            convertValue(k, fromType, type.keyType(), keyFieldId, wrapper),
                            convertValue(v, fromType, type.valueType(), valueFieldId, wrapper));
                });
        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(

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Fix upstream data/types so int fields carry numeric values (or numeric strings).
  2. Pre-cast the field in a transform (e.g. CAST(col AS INT)).
  3. Change the Iceberg column type to match the actual data type.
  4. Catch IllegalArgumentException and handle/redirect bad records.

Example fix

// before
row.setField(0, true); // int field
// after
row.setField(0, 1); // or cast boolean to int upstream
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(v instanceof Number) && !(v instanceof String)) { throw new IllegalArgumentException("int field expects Number/String, got " + v.getClass()); }

Type guard

Integer safeToInt(Object v) { if (v instanceof Number) return ((Number) v).intValue(); if (v instanceof String) return Integer.valueOf((String) v); return null; }

Try / catch

try { value = convertInt(raw); } catch (IllegalArgumentException e) { log.warn("Bad int value: {}", e.getMessage()); }

Prevention

When it happens

Trigger: convertValue targeting an Iceberg IntegerType field receives a value that is neither Number nor String, e.g. a Boolean or Date from upstream data.

Common situations: Schema mismatches where upstream passes booleans/dates into int columns; CSV/JSON parsers producing unexpected Java types (e.g. boolean for 0/1).

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


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/12a06ca316010718. Report an issue: GitHub.