apache/flink · error · InvalidTypesException
The given class is no array.
Error message
The given class is no array.
What it means
PrimitiveArrayTypeInfo.getInfoFor(Class) checks type.isArray() and throws InvalidTypesException if the class is not an array. This factory only resolves primitive arrays (int[], long[], double[], etc.). Passing a non-array class, a boxed-array (Integer[]), or a Collection is a type-dispatch error. Boxed arrays belong to BasicArrayTypeInfo; non-arrays to TypeExtractor.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/common/typeinfo/PrimitiveArrayTypeInfo.java:244
return obj instanceof PrimitiveArrayTypeInfo;
}
// --------------------------------------------------------------------------------------------
/**
* Tries to get the PrimitiveArrayTypeInfo for an array. Returns null, if the type is an array,
* but the component type is not a primitive type.
*
* @param type The class of the array.
* @return The corresponding PrimitiveArrayTypeInfo, or null, if the array is not an array of
* primitives.
* @throws InvalidTypesException Thrown, if the given class does not represent an array.
*/
@SuppressWarnings("unchecked")
@PublicEvolving
public static <X> PrimitiveArrayTypeInfo<X> getInfoFor(Class<X> type) {
if (!type.isArray()) {
throw new InvalidTypesException("The given class is no array.");
}
// basic type arrays
return (PrimitiveArrayTypeInfo<X>) TYPES.get(type);
}
/** Static map from array class to type info. */
private static final Map<Class<?>, PrimitiveArrayTypeInfo<?>> TYPES = new HashMap<>();
// initialization of the static map
static {
TYPES.put(boolean[].class, BOOLEAN_PRIMITIVE_ARRAY_TYPE_INFO);
TYPES.put(byte[].class, BYTE_PRIMITIVE_ARRAY_TYPE_INFO);
TYPES.put(short[].class, SHORT_PRIMITIVE_ARRAY_TYPE_INFO);
TYPES.put(int[].class, INT_PRIMITIVE_ARRAY_TYPE_INFO);
TYPES.put(long[].class, LONG_PRIMITIVE_ARRAY_TYPE_INFO);
TYPES.put(float[].class, FLOAT_PRIMITIVE_ARRAY_TYPE_INFO);
TYPES.put(double[].class, DOUBLE_PRIMITIVE_ARRAY_TYPE_INFO);View on GitHub (pinned to 2f3c205e92)
Solutions
- Guard with type.isArray() && type.getComponentType().isPrimitive() before calling getInfoFor.
- For boxed arrays use BasicArrayTypeInfo.getInfoFor; for non-arrays use TypeExtractor.createTypeInfo.
- Prefer TypeInformation.of(TypeHint) or TypeExtractor for generic dispatch instead of calling PrimitiveArrayTypeInfo directly.
Example fix
// before PrimitiveArrayTypeInfo.getInfoFor(Integer[].class); // boxed, not primitive array // after BasicArrayTypeInfo.getInfoFor(Integer[].class); // or for true primitive arrays: PrimitiveArrayTypeInfo.getInfoFor(int[].class);
Defensive patterns
Strategy: type-guard
Validate before calling
Class<?> c = ...;
if (!c.isArray() || !c.getComponentType().isPrimitive()) {
throw new IllegalArgumentException(c + " is not a primitive array");
}
PrimitiveArrayTypeInfo.getInfoFor(c); Type guard
static boolean isPrimitiveArray(Class<?> c) {
return c.isArray() && c.getComponentType().isPrimitive();
} Try / catch
try {
return PrimitiveArrayTypeInfo.getInfoFor(type);
} catch (InvalidTypesException e) {
return TypeExtractor.createTypeInfo(type);
} Prevention
- Check isArray() && componentType.isPrimitive() before calling PrimitiveArrayTypeInfo.getInfoFor.
- Use TypeExtractor.createTypeInfo for generic dispatch.
- Remember Integer[] is BasicArray, int[] is PrimitiveArray.
When it happens
Trigger: Calling PrimitiveArrayTypeInfo.getInfoFor with a non-array class; passing Integer[].class (boxed) instead of int[].class (primitive); routing a List or POJO through this factory by mistake.
Common situations: Custom type extractors that assume a class is a primitive array without verifying; confusion between int[] and Integer[]; generic code that picks the wrong array-type factory.
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/995afa8c9cd7de01.
Report an issue: GitHub.