{"record":{"id":"3eaf93d07287ea1a","repo":"apache/flink","slug":"invalid-element-type-for-a-primitive-array","errorCode":null,"errorMessage":"Invalid element type for a primitive array.","messagePattern":"Invalid element type for a primitive array\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/typeinfo/Types.java","lineNumber":386,"sourceCode":"    public static TypeInformation<?> PRIMITIVE_ARRAY(TypeInformation<?> elementType) {\n        if (elementType == BOOLEAN) {\n            return PrimitiveArrayTypeInfo.BOOLEAN_PRIMITIVE_ARRAY_TYPE_INFO;\n        } else if (elementType == BYTE) {\n            return PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO;\n        } else if (elementType == SHORT) {\n            return PrimitiveArrayTypeInfo.SHORT_PRIMITIVE_ARRAY_TYPE_INFO;\n        } else if (elementType == INT) {\n            return PrimitiveArrayTypeInfo.INT_PRIMITIVE_ARRAY_TYPE_INFO;\n        } else if (elementType == LONG) {\n            return PrimitiveArrayTypeInfo.LONG_PRIMITIVE_ARRAY_TYPE_INFO;\n        } else if (elementType == FLOAT) {\n            return PrimitiveArrayTypeInfo.FLOAT_PRIMITIVE_ARRAY_TYPE_INFO;\n        } else if (elementType == DOUBLE) {\n            return PrimitiveArrayTypeInfo.DOUBLE_PRIMITIVE_ARRAY_TYPE_INFO;\n        } else if (elementType == CHAR) {\n            return PrimitiveArrayTypeInfo.CHAR_PRIMITIVE_ARRAY_TYPE_INFO;\n        }\n        throw new IllegalArgumentException(\"Invalid element type for a primitive array.\");\n    }\n\n    /**\n     * Returns type information for Java arrays of object types (such as <code>String[]</code>,\n     * <code>Integer[]</code>). The array itself must not be null. Null values for elements are\n     * supported.\n     *\n     * @param elementType element type of the array\n     */\n    @SuppressWarnings(\"unchecked\")\n    public static <E> TypeInformation<E[]> OBJECT_ARRAY(TypeInformation<E> elementType) {\n        if (elementType == Types.STRING) {\n            return (TypeInformation) BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO;\n        }\n        return ObjectArrayTypeInfo.getInfoFor(elementType);\n    }\n\n    /**","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/typeinfo/Types.java#L368-L404","documentation":"Thrown by Types.PRIMITIVE_ARRAY(TypeInformation) when the supplied elementType is not one of the eight supported primitive element types (BOOLEAN, BYTE, SHORT, INT, LONG, FLOAT, DOUBLE, CHAR). The method uses reference equality (==) against the canonical Types constants, so even an equivalent TypeInformation that is not the exact singleton instance will fail.","triggerScenarios":"Passing Types.STRING, Types.SQL_DATE, Types.LOCAL_DATE_TIME, a POJO/ROW/TUPLE type, or a custom TypeInformation to PRIMITIVE_ARRAY. Also triggered by passing a TypeInformation that represents a boxed type wrapper created via a different path (e.g. BasicTypeInfo.INT_TYPE_INFO instead of Types.INT — though these happen to be the same singleton, any non-singleton equivalent would fail).","commonSituations":"Confusing PRIMITIVE_ARRAY (int[]) with OBJECT_ARRAY (Integer[]). Passing Types.STRING expecting a String[] (use OBJECT_ARRAY instead). Constructing element type info dynamically and not narrowing to one of the eight primitives. Reading element type from a schema descriptor that yields a non-primitive.","solutions":["Use only one of Types.BOOLEAN, Types.BYTE, Types.SHORT, Types.INT, Types.LONG, Types.FLOAT, Types.DOUBLE, Types.CHAR as the elementType.","If you need an array of objects (String[], Integer[], POJO[]), use Types.OBJECT_ARRAY(elementType) instead.","If the element type is dynamic, switch on its BasicTypeInfo/SqlTimeTypeInfo class and fall back to OBJECT_ARRAY for non-primitives."],"exampleFix":"// before — String is not a primitive element type\nTypeInformation<?> ti = Types.PRIMITIVE_ARRAY(Types.STRING); // throws\n\n// after — use OBJECT_ARRAY for object arrays\nTypeInformation<String[]> ti = Types.OBJECT_ARRAY(Types.STRING); // ok\n\n// correct primitive array usage\nTypeInformation<int[]> ti = Types.PRIMITIVE_ARRAY(Types.INT); // ok","handlingStrategy":"validation","validationCode":"private static final Set<TypeInformation<?>> PRIMITIVE_ELEMENT_TYPES = Set.of(\n        Types.BOOLEAN, Types.BYTE, Types.SHORT, Types.INT,\n        Types.LONG, Types.FLOAT, Types.DOUBLE, Types.CHAR\n);\n\nif (!PRIMITIVE_ELEMENT_TYPES.contains(elementType)) {\n    // use OBJECT_ARRAY for non-primitive element types\n    ti = Types.OBJECT_ARRAY(elementType);\n} else {\n    ti = Types.PRIMITIVE_ARRAY(elementType);\n}","typeGuard":null,"tryCatchPattern":"try {\n    ti = Types.PRIMITIVE_ARRAY(elementType);\n} catch (IllegalArgumentException e) {\n    // element type is not a primitive — fall back to object array\n    ti = Types.OBJECT_ARRAY(elementType);\n}","preventionTips":["Remember PRIMITIVE_ARRAY is for byte[], int[], etc. — use OBJECT_ARRAY for String[], Integer[], POJO[].","Pin the element type to one of the Types primitive constants, never a dynamically-built TypeInformation."],"tags":["type-system","array","type-info","illegal-argument"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}