apache/iceberg · error · IllegalArgumentException

Cannot convert to double

Error message

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

What it means

convertDouble coerces Connect values to Iceberg DoubleType fields: accepts Number (doubleValue()) and String (Double.parseDouble). Any other class throws IllegalArgumentException with the value's class name.

Solutions

  1. Fix the producer to emit numbers or numeric strings for double fields.
  2. Adjust the Iceberg schema so the column type matches the data.
  3. Use a transformation to convert values before the sink.
  4. Handle IllegalArgumentException by diverting the record to a DLQ.

Example fix

// before
record.set("amount", new byte[] {1, 2}); // byte[] into DoubleType
// after
record.set("amount", 42.5d);
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

boolean isDoubleConvertible(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 double")) {
    sendToDlq(record, e);
  } else throw e;
}

Prevention

When it happens

Trigger: A field mapped to an Iceberg DoubleType column holding a Boolean, byte[], collection, or other non-numeric non-string value.

Common situations: Double columns receiving booleans from schemaless JSON; producer type drift from double to string-encoded data not parseable as a number (which instead throws NumberFormatException deeper in parsing).

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/e145913270ed22cc. Report an issue: GitHub.

Appendix: source

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

    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);
    }
    throw new IllegalArgumentException("Cannot convert to double: " + value.getClass().getName());
  }

  protected BigDecimal convertDecimal(Object value, DecimalType type) {
    BigDecimal bigDecimal;
    if (value instanceof BigDecimal) {
      bigDecimal = (BigDecimal) value;
    } else if (value instanceof Number) {
      Number num = (Number) value;
      Double dbl = num.doubleValue();
      if (dbl.equals(Math.floor(dbl))) {
        bigDecimal = BigDecimal.valueOf(num.longValue());
      } else {
        bigDecimal = BigDecimal.valueOf(dbl);
      }
    } else if (value instanceof String) {
      bigDecimal = new BigDecimal((String) value);
    } else {
      throw new IllegalArgumentException(

View on GitHub (pinned to 86d9c8fc54)