apache/seatunnel · error · IllegalArgumentException

Cannot convert to double:

Error message

Cannot convert to double: 

What it means

Thrown by RowConverter.convertDouble when an Iceberg field value being converted to a double is neither a Number nor a parseable String; the message names the value's Java class, identifying the incompatible source type.

Source

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

    }

    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, Types.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 {

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Normalize upstream values to numeric or numeric-string form.
  2. Pre-cast with a transform: CAST(col AS DOUBLE).
  3. Change the Iceberg column type to match the actual data type.
  4. Catch IllegalArgumentException for error routing.

Example fix

// before
row.setField(0, true); // double field
// after
row.setField(0, 1.0d);
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

Double safeToDouble(Object v) { if (v instanceof Number) return ((Number) v).doubleValue(); if (v instanceof String) return Double.valueOf((String) v); return null; }

Try / catch

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

Prevention

When it happens

Trigger: convertValue targeting an Iceberg DoubleType field receives a value that is neither Number nor String (e.g. Boolean, byte[], LocalDate).

Common situations: Date/time objects in DOUBLE columns, booleans from parsers, misaligned schema between source and Iceberg table.

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