apache/flink · error · InvalidTypesException
The given class is no array.
Error message
The given class is no array.
What it means
BasicArrayTypeInfo.getInfoFor(Class) checks type.isArray() and throws InvalidTypesException if the class is not an array. This factory resolves only boxed-primitive and String wrapper arrays (Boolean[], Byte[], String[], etc.) to their BasicArrayTypeInfo. Passing any non-array class (a List, a POJO, a scalar) violates the precondition.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/common/typeinfo/BasicArrayTypeInfo.java:173
}
@Override
public boolean canEqual(Object obj) {
return obj instanceof BasicArrayTypeInfo;
}
@Override
public String toString() {
return this.getClass().getSimpleName() + "<" + componentInfo + ">";
}
// --------------------------------------------------------------------------------------------
@SuppressWarnings("unchecked")
@PublicEvolving
public static <X, C> BasicArrayTypeInfo<X, C> getInfoFor(Class<X> type) {
if (!type.isArray()) {
throw new InvalidTypesException("The given class is no array.");
}
// basic type arrays
return (BasicArrayTypeInfo<X, C>) TYPES.get(type);
}
private static final Map<Class<?>, BasicArrayTypeInfo<?, ?>> TYPES = new HashMap<>();
static {
TYPES.put(String[].class, STRING_ARRAY_TYPE_INFO);
TYPES.put(Boolean[].class, BOOLEAN_ARRAY_TYPE_INFO);
TYPES.put(Byte[].class, BYTE_ARRAY_TYPE_INFO);
TYPES.put(Short[].class, SHORT_ARRAY_TYPE_INFO);
TYPES.put(Integer[].class, INT_ARRAY_TYPE_INFO);
TYPES.put(Long[].class, LONG_ARRAY_TYPE_INFO);
TYPES.put(Float[].class, FLOAT_ARRAY_TYPE_INFO);
TYPES.put(Double[].class, DOUBLE_ARRAY_TYPE_INFO);
TYPES.put(Character[].class, CHAR_ARRAY_TYPE_INFO);View on GitHub (pinned to 2f3c205e92)
Solutions
- Guard with type.isArray() before calling getInfoFor; route non-arrays to the appropriate factory (TypeExtractor, PojoTypeInfo, etc.).
- For primitive arrays, use PrimitiveArrayTypeInfo.getInfoFor instead; for object arrays of non-basic types, use TypeExtractor.createTypeInfo.
- Prefer the higher-level TypeInformation.of(TypeHint) or TypeExtractor.createTypeInfo, which dispatch correctly, over calling BasicArrayTypeInfo.getInfoFor directly.
Example fix
// before
BasicArrayTypeInfo.getInfoFor(MyPojo.class); // throws
// after
if (type.isArray()) {
BasicArrayTypeInfo.getInfoFor(type);
} else {
TypeExtractor.createTypeInfo(type);
} Defensive patterns
Strategy: type-guard
Validate before calling
Class<?> c = ...;
if (!c.isArray()) {
throw new IllegalArgumentException(c + " is not an array");
}
BasicArrayTypeInfo.getInfoFor(c); Type guard
static boolean isBasicObjectArray(Class<?> c) {
return c.isArray() && !c.getComponentType().isPrimitive();
} Try / catch
// Prefer dispatch via TypeExtractor rather than catching
try {
return BasicArrayTypeInfo.getInfoFor(type);
} catch (InvalidTypesException e) {
return TypeExtractor.createTypeInfo(type);
} Prevention
- Route all class-to-TypeInformation calls through TypeExtractor.createTypeInfo, which dispatches correctly.
- Check isArray() and component-type primitives before choosing BasicArray vs PrimitiveArray factory.
- Avoid calling BasicArrayTypeInfo.getInfoFor directly unless you know the class is an object array.
When it happens
Trigger: Calling BasicArrayTypeInfo.getInfoFor(someClass) where someClass is a Collection, a POJO, or a scalar; reflection-driven code that routes arbitrary classes through this factory without first checking isArray().
Common situations: Custom type-info builders that dispatch to BasicArrayTypeInfo without an isArray guard; serializing a field typed as List<T> or T (erased) and landing on this factory; misclassifying a POJO array vs. a basic array.
Related errors
- The given class is no array.
- Tuple type expected but was: {}
- Return type {keyType} of KeySelector {keyExtractor.getClass(
- Class is not a TypeInfoFactory.
- Could not create the type information for '{}'. The most com
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/543132640c9061da.
Report an issue: GitHub.