apache/flink · error · InvalidTypesException

Object array type expected.

Error message

Object array type expected.

What it means

Thrown by TypeExtractor.validateInfo when an ObjectArrayTypeInfo is expected but the extracted Java type is neither a Class array nor a GenericArrayType. This means the type extractor expected an object array (e.g., MyPojo[]) but the reflected type was not recognized as an array at all.

Source

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

                if (component instanceof TypeVariable<?>) {
                    component = materializeTypeVariable(typeHierarchy, (TypeVariable<?>) component);
                    if (component instanceof TypeVariable) {
                        return;
                    }
                }

                validateInfo(
                        typeHierarchy,
                        component,
                        ((BasicArrayTypeInfo<?, ?>) typeInfo).getComponentInfo());

            }
            // check for object array
            else if (typeInfo instanceof ObjectArrayTypeInfo<?, ?>) {
                // check if array at all
                if (!(type instanceof Class<?> && ((Class<?>) type).isArray())
                        && !(type instanceof GenericArrayType)) {
                    throw new InvalidTypesException("Object array type expected.");
                }

                // check component
                Type component;
                if (type instanceof Class<?>) {
                    component = ((Class<?>) type).getComponentType();
                } else {
                    component = ((GenericArrayType) type).getGenericComponentType();
                }

                if (component instanceof TypeVariable<?>) {
                    component = materializeTypeVariable(typeHierarchy, (TypeVariable<?>) component);
                    if (component instanceof TypeVariable) {
                        return;
                    }
                }

                validateInfo(

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Declare the return type as a concrete object array (e.g., MyPojo[]) in the UDF signature.
  2. Provide explicit TypeInformation using .returns(TypeInformation.of(new TypeHint<MyPojo[]>(){})).
  3. Avoid using List/Collection in signatures where an object array type info is expected; align the declared type with the actual runtime type.
  4. If generics are the problem, use a non-generic subclass to preserve type information for the extractor.

Example fix

// before
public T[] map(MyRecord r) { ... } // T[] with erasure fails
// after
public MyPojo[] map(MyRecord r) { ... }
// or
.returns(TypeInformation.of(new TypeHint<MyPojo[]>(){}))
Defensive patterns

Strategy: validation

Validate before calling

// Check that the type is an array before extraction
Type type = method.getGenericReturnType();
boolean isObjectArray = (type instanceof Class<?> && ((Class<?>) type).isArray())
    || (type instanceof GenericArrayType);
if (!isObjectArray) {
    ti = TypeInformation.of(new TypeHint<MyPojo[]>(){});
}

Type guard

static boolean isObjectArrayType(Type t) {
    return (t instanceof Class<?> && ((Class<?>) t).isArray())
        || (t instanceof GenericArrayType);
}

Try / catch

try {
    TypeInformation<?> ti = TypeExtractor.createTypeInfo(myFunction.getClass());
} catch (InvalidTypesException e) {
    ti = TypeInformation.of(new TypeHint<MyPojo[]>(){});
}

Prevention

When it happens

Trigger: Called during validateInfo when the TypeInformation is an ObjectArrayTypeInfo but the reflected Type is not Class.isArray() and not a GenericArrayType. This happens when a UDF signature declares a custom object array but the type argument is erased, a raw type, a TypeVariable, or a Collection instead.

Common situations: Returning List<MyPojo> where MyPojo[] was expected, or using raw types / generic type variables that do not carry array info at runtime. Common in generic base classes where the type parameter T[] loses its array nature through erasure.

Related errors


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