apache/flink · error · InvalidTypesException

Array type expected.

Error message

Array type expected.

What it means

Thrown during input type validation when the TypeInformation is PrimitiveArrayTypeInfo (for arrays of Java primitives like int[], byte[], double[]) but the reflected Type is neither a Class array nor a GenericArrayType. This means the function expects a primitive array input but the actual type is a scalar, a POJO, or some other non-array type.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java:1586

                                    + subTypes.length
                                    + "'.");
                }

                for (int i = 0; i < subTypes.length; i++) {
                    validateInfo(new ArrayList<>(typeHierarchy), subTypes[i], tti.getTypeAt(i));
                }
            }
            // check for primitive array
            else if (typeInfo instanceof PrimitiveArrayTypeInfo) {
                Type component;
                // check if array at all
                if (!(type instanceof Class<?>
                                && ((Class<?>) type).isArray()
                                && (component = ((Class<?>) type).getComponentType()) != null)
                        && !(type instanceof GenericArrayType
                                && (component = ((GenericArrayType) type).getGenericComponentType())
                                        != null)) {
                    throw new InvalidTypesException("Array type expected.");
                }
                if (component instanceof TypeVariable<?>) {
                    component = materializeTypeVariable(typeHierarchy, (TypeVariable<?>) component);
                    if (component instanceof TypeVariable) {
                        return;
                    }
                }
                if (!(component instanceof Class<?> && ((Class<?>) component).isPrimitive())) {
                    throw new InvalidTypesException("Primitive component expected.");
                }
            }
            // check for basic array
            else if (typeInfo instanceof BasicArrayTypeInfo<?, ?>) {
                Type component;
                // check if array at all
                if (!(type instanceof Class<?>
                                && ((Class<?>) type).isArray()
                                && (component = ((Class<?>) type).getComponentType()) != null)

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Align the function's input type to match the primitive array type of the stream
  2. Add a conversion map to transform the stream element to a primitive array before the function
  3. If the stream carries objects, change the function to accept the object type and extract the array internally

Example fix

// before — expects byte[], stream carries String
DataStream<String> stream = ...;
stream.map(new MapFunction<byte[], X>() { ... });

// after — align types
stream.map(s -> s.getBytes(StandardCharsets.UTF_8))
      .map(new MapFunction<byte[], X>() { ... });
Defensive patterns

Strategy: validation

Validate before calling

// Verify stream type is a primitive array when function expects one
if (stream.getType() instanceof PrimitiveArrayTypeInfo) {
    Class<?> componentClass =
        ((PrimitiveArrayTypeInfo<?>) stream.getType()).getComponentType();
    // Function signature should use matching primitive array
    if (!myFunctionInputClass.isArray()
            || !myFunctionInputClass.getComponentType().isPrimitive()) {
        throw new IllegalStateException(
            "Stream carries primitive array but function input "
            + myFunctionInputClass + " is not a primitive array");
    }
}

Prevention

When it happens

Trigger: A function declares a primitive array input (e.g. `MapFunction<byte[], X>`) but the DataStream carries a non-array type. Or the stream's TypeInformation is PrimitiveArrayTypeInfo but the function's reflected type is not an array at all — it is a plain class or parameterized type.

Common situations: Connecting a function that processes byte[] (common for binary data, image processing) to a stream of Strings or POJOs. Mismatch between a source emitting primitive arrays and a function expecting objects. Using a KeyDeserialization that produces primitive arrays with a function expecting objects.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/efbe77da291c38ba. Report an issue: GitHub.