apache/flink · error · InvalidTypesException
Primitive component expected.
Error message
Primitive component expected.
What it means
Thrown during input type validation for PrimitiveArrayTypeInfo when the array component type is not a Java primitive. The TypeInformation declares a primitive array (e.g. int[]) but the reflected component type is a non-primitive class (e.g. Integer, String, or a custom class). Only true primitives (byte, short, int, long, float, double, char, boolean) are valid components for PrimitiveArrayTypeInfo.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java:1595
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)
&& !(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) {View on GitHub (pinned to 2f3c205e92)
Solutions
- Use primitive array types in the function signature: `int[]` not `Integer[]`, `byte[]` not `Byte[]`
- If the stream genuinely carries boxed arrays, use BasicArrayTypeInfo instead of PrimitiveArrayTypeInfo
- Add a conversion map to unbox the array: `Arrays.stream(arr).mapToInt(Integer::intValue).toArray()`
Example fix
// before — boxed array where primitive expected
public class MyFunc extends MapFunction<Integer[], X> { ... }
// after — primitive array
public class MyFunc extends MapFunction<int[], X> {
public X map(int[] values) { ... }
} Defensive patterns
Strategy: validation
Validate before calling
// Verify the array component is a primitive, not a wrapper
Class<?> funcInputClass = myFunctionInputClass;
if (funcInputClass.isArray()) {
Class<?> component = funcInputClass.getComponentType();
if (!component.isPrimitive()) {
throw new IllegalArgumentException(
"Function uses boxed array " + funcInputClass.getName()
+ ". Use primitive array instead: e.g. int[] not Integer[].");
}
} Prevention
- Always use primitive arrays (int[], byte[], double[]) not boxed arrays (Integer[], Byte[])
- Use IDE inspections or Checkstyle rules to flag boxed array usage in Flink functions
- Convert boxed arrays to primitive arrays explicitly before connecting to the stream
- Remember the eight primitive types: byte, short, int, long, float, double, char, boolean
When it happens
Trigger: A function declares `MapFunction<int[], X>` but the reflected array type has a wrapper component (e.g. `Integer[]` instead of `int[]`). Or the stream's TypeInformation is PrimitiveArrayTypeInfo but the function signature uses a wrapper array type. The check `((Class<?>) component).isPrimitive()` fails for wrapper types.
Common situations: Using `Integer[]` (wrapper array) where `int[]` (primitive array) is expected. Mixing Java boxed and unboxed array types. Connecting a function with `Double[]` to a stream carrying `double[]`. Generic type erasure converting a primitive array to a boxed array in certain reflection scenarios.
Related errors
- Array type expected.
- Basic type expected.
- Basic type '{}' expected but was '{}'.
- SQL time type expected.
- SQL time type '{}' expected but was '{}'.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/bd9152f7cbec2a25.
Report an issue: GitHub.