apache/seatunnel · error · UnsupportedOperationException

Unsupported convert ${value.getClass()} to byte[]

Error message

Unsupported convert ${value.getClass()} to byte[]

What it means

This parameterless convertBytes overload handles ByteBuffer and String only, then throws UnsupportedOperationException for any other class. Unlike error 85 it does not accept byte[] passthrough or include a typeDefine in the message. It signals a raw-type conversion attempt that the utility deliberately does not guess at.

Source

Thrown at seatunnel-api/src/main/java/org/apache/seatunnel/api/table/converter/BasicDataConverter.java:391

                        + " to byte[], typeDefine: "
                        + typeDefine);
    }

    default byte[] convertBytes(T typeDefine, String value) {
        return convertBytes(value);
    }

    default byte[] convertBytes(Object value) throws UnsupportedOperationException {
        if (value instanceof byte[]) {
            return (byte[]) value;
        }
        if (value instanceof ByteBuffer) {
            return convertBytes((ByteBuffer) value);
        }
        if (value instanceof String) {
            return convertBytes((String) value);
        }
        throw new UnsupportedOperationException(
                "Unsupported convert " + value.getClass() + " to byte[]");
    }

    default byte[] convertBytes(ByteBuffer value) {
        byte[] bytes = new byte[value.remaining()];
        value.get(bytes);
        return bytes;
    }

    default byte[] convertBytes(String value) {
        return value.getBytes();
    }

    default LocalDateTime convertLocalDateTime(T typeDefine, Object value)
            throws UnsupportedOperationException {
        if (value instanceof LocalDateTime) {
            return (LocalDateTime) value;
        }

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Copy the data into a ByteBuffer.wrap(...) or a String (with an explicit charset) before calling convertBytes.
  2. Use the typeDefine-aware overload convertBytes(typeDefine, value) if your input is a byte[].
  3. Override convertBytes in a converter subclass to add support for your buffer type (e.g. ByteBuf.array()).
  4. Ensure the data is actually binary; otherwise use convertString and a STRING column.

Example fix

// before
converter.convertBytes(nettyByteBuf);
// after
converter.convertBytes(ByteBuffer.wrap(nettyByteBuf.array(), nettyByteBuf.arrayOffset(), nettyByteBuf.readableBytes()));
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(value instanceof ByteBuffer) && !(value instanceof String)) {
    throw new IllegalArgumentException("convertBytes(Object) accepts only ByteBuffer/String, got " + value.getClass());
}

Type guard

boolean isByteBufferOrString(Object v) { return v instanceof ByteBuffer || v instanceof String; }

Try / catch

try {
    return converter.convertBytes(value);
} catch (UnsupportedOperationException e) {
    LOG.warn("Raw bytes conversion failed: {}", e.getMessage());
    return null;
}

Prevention

When it happens

Trigger: Calling convertBytes(Object value) directly with an Integer, char[], List<Byte>, InputStream, or similar that is neither ByteBuffer nor String.

Common situations: Reading bytes from a stream or a legacy buffer type (e.g. Netty ByteBuf) and passing them straight in; assuming the overload accepts byte[] like its typeDefine-aware sibling; char[] from password-style APIs.

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