apache/iceberg · error · IllegalArgumentException

Cannot convert to int

Error message

Cannot convert to int: ${value.getClass().getName()}

What it means

convertInt coerces Connect values to Iceberg Integer fields: it accepts Number (via intValue()) and String (via Integer.parseInt). Anything else — Boolean, byte[], List, Map, etc. — throws IllegalArgumentException naming the value's class.

Solutions

  1. Fix the producer so the field sends a numeric or numeric-string value.
  2. Change the Iceberg column type to match the actual value type (e.g. BooleanType).
  3. Pre-clean the value in a transform/SMT to convert or default it before the sink.
  4. Catch IllegalArgumentException and route the record to a DLQ.

Example fix

// before
record.set("count", true); // boolean into IntegerType
// after
record.set("count", 1); // or change column to BOOLEAN
Defensive patterns

Strategy: validation

Validate before calling

Object v = record.get("count");
if (!(v instanceof Number) && !(v instanceof String)) {
  throw new IllegalArgumentException("count must be numeric, got " + v.getClass().getSimpleName());
}

Type guard

boolean isIntConvertible(Object v) {
  return v instanceof Number || v instanceof String;
}

Try / catch

try {
  sink.write(record);
} catch (IllegalArgumentException e) {
  if (e.getMessage() != null && e.getMessage().contains("Cannot convert to int")) {
    sendToDlq(record, e);
  } else throw e;
}

Prevention

When it happens

Trigger: Writing a record whose field mapped to an Iceberg IntegerType column holds a Boolean, byte[], collection, or other non-numeric non-string value.

Common situations: JSON payloads with booleans/objects in integer fields; schema registry schema mismatch; producer type changed from int to boolean without updating the table schema.

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/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/1b4a5756a7ac22b4. Report an issue: GitHub.

Appendix: source

Thrown at kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java:429

    int valueFieldId = type.fields().get(1).fieldId();
    Type keyType = type.keyType();
    Type valueType = type.valueType();
    Map<Object, Object> result = Maps.newHashMapWithExpectedSize(map.size());
    map.forEach(
        (k, v) ->
            result.put(
                convertValue(k, keyType, keyFieldId, schemaUpdateConsumer),
                convertValue(v, valueType, valueFieldId, schemaUpdateConsumer)));
    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());

View on GitHub (pinned to 86d9c8fc54)