{"record":{"id":"efbe77da291c38ba","repo":"apache/flink","slug":"array-type-expected","errorCode":null,"errorMessage":"Array type expected.","messagePattern":"Array type expected\\.","errorType":"exception","errorClass":"InvalidTypesException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java","lineNumber":1586,"sourceCode":"                                    + subTypes.length\n                                    + \"'.\");\n                }\n\n                for (int i = 0; i < subTypes.length; i++) {\n                    validateInfo(new ArrayList<>(typeHierarchy), subTypes[i], tti.getTypeAt(i));\n                }\n            }\n            // check for primitive array\n            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)","sourceCodeStart":1568,"sourceCodeEnd":1604,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java#L1568-L1604","documentation":"Thrown during input type validation when the TypeInformation is PrimitiveArrayTypeInfo (for arrays of Java primitives like int[], byte[], double[]) but the reflected Type is neither a Class array nor a GenericArrayType. This means the function expects a primitive array input but the actual type is a scalar, a POJO, or some other non-array type.","triggerScenarios":"A function declares a primitive array input (e.g. `MapFunction<byte[], X>`) but the DataStream carries a non-array type. Or the stream's TypeInformation is PrimitiveArrayTypeInfo but the function's reflected type is not an array at all — it is a plain class or parameterized type.","commonSituations":"Connecting a function that processes byte[] (common for binary data, image processing) to a stream of Strings or POJOs. Mismatch between a source emitting primitive arrays and a function expecting objects. Using a KeyDeserialization that produces primitive arrays with a function expecting objects.","solutions":["Align the function's input type to match the primitive array type of the stream","Add a conversion map to transform the stream element to a primitive array before the function","If the stream carries objects, change the function to accept the object type and extract the array internally"],"exampleFix":"// before — expects byte[], stream carries String\nDataStream<String> stream = ...;\nstream.map(new MapFunction<byte[], X>() { ... });\n\n// after — align types\nstream.map(s -> s.getBytes(StandardCharsets.UTF_8))\n      .map(new MapFunction<byte[], X>() { ... });","handlingStrategy":"validation","validationCode":"// Verify stream type is a primitive array when function expects one\nif (stream.getType() instanceof PrimitiveArrayTypeInfo) {\n    Class<?> componentClass =\n        ((PrimitiveArrayTypeInfo<?>) stream.getType()).getComponentType();\n    // Function signature should use matching primitive array\n    if (!myFunctionInputClass.isArray()\n            || !myFunctionInputClass.getComponentType().isPrimitive()) {\n        throw new IllegalStateException(\n            \"Stream carries primitive array but function input \"\n            + myFunctionInputClass + \" is not a primitive array\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure function input array types match the stream's PrimitiveArrayTypeInfo","Add explicit conversion maps when transforming between object and primitive arrays","Use Types.PRIMITIVE_ARRAY(Types.INT) to construct expected type info for validation","Document the expected primitive array type in function JavaDoc"],"tags":["type-validation","primitive-array","type-mismatch","reflection","array"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}