{"record":{"id":"bd9152f7cbec2a25","repo":"apache/flink","slug":"primitive-component-expected","errorCode":null,"errorMessage":"Primitive component expected.","messagePattern":"Primitive component expected\\.","errorType":"exception","errorClass":"InvalidTypesException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java","lineNumber":1595,"sourceCode":"            else if (typeInfo instanceof PrimitiveArrayTypeInfo) {\n                Type component;\n                // check if array at all\n                if (!(type instanceof Class<?>\n                                && ((Class<?>) type).isArray()\n                                && (component = ((Class<?>) type).getComponentType()) != null)\n                        && !(type instanceof GenericArrayType\n                                && (component = ((GenericArrayType) type).getGenericComponentType())\n                                        != null)) {\n                    throw new InvalidTypesException(\"Array type expected.\");\n                }\n                if (component instanceof TypeVariable<?>) {\n                    component = materializeTypeVariable(typeHierarchy, (TypeVariable<?>) component);\n                    if (component instanceof TypeVariable) {\n                        return;\n                    }\n                }\n                if (!(component instanceof Class<?> && ((Class<?>) component).isPrimitive())) {\n                    throw new InvalidTypesException(\"Primitive component expected.\");\n                }\n            }\n            // check for basic array\n            else if (typeInfo instanceof BasicArrayTypeInfo<?, ?>) {\n                Type component;\n                // check if array at all\n                if (!(type instanceof Class<?>\n                                && ((Class<?>) type).isArray()\n                                && (component = ((Class<?>) type).getComponentType()) != null)\n                        && !(type instanceof GenericArrayType\n                                && (component = ((GenericArrayType) type).getGenericComponentType())\n                                        != null)) {\n                    throw new InvalidTypesException(\"Array type expected.\");\n                }\n\n                if (component instanceof TypeVariable<?>) {\n                    component = materializeTypeVariable(typeHierarchy, (TypeVariable<?>) component);\n                    if (component instanceof TypeVariable) {","sourceCodeStart":1577,"sourceCodeEnd":1613,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java#L1577-L1613","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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()`"],"exampleFix":"// before — boxed array where primitive expected\npublic class MyFunc extends MapFunction<Integer[], X> { ... }\n\n// after — primitive array\npublic class MyFunc extends MapFunction<int[], X> {\n    public X map(int[] values) { ... }\n}","handlingStrategy":"validation","validationCode":"// Verify the array component is a primitive, not a wrapper\nClass<?> funcInputClass = myFunctionInputClass;\nif (funcInputClass.isArray()) {\n    Class<?> component = funcInputClass.getComponentType();\n    if (!component.isPrimitive()) {\n        throw new IllegalArgumentException(\n            \"Function uses boxed array \" + funcInputClass.getName()\n            + \". Use primitive array instead: e.g. int[] not Integer[].\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["type-validation","primitive-array","type-mismatch","boxing","reflection","array"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}