{"record":{"id":"995afa8c9cd7de01","repo":"apache/flink","slug":"the-given-class-is-no-array-995afa","errorCode":null,"errorMessage":"The given class is no array.","messagePattern":"The given class is no array\\.","errorType":"exception","errorClass":"InvalidTypesException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/typeinfo/PrimitiveArrayTypeInfo.java","lineNumber":244,"sourceCode":"        return obj instanceof PrimitiveArrayTypeInfo;\n    }\n\n    // --------------------------------------------------------------------------------------------\n\n    /**\n     * Tries to get the PrimitiveArrayTypeInfo for an array. Returns null, if the type is an array,\n     * but the component type is not a primitive type.\n     *\n     * @param type The class of the array.\n     * @return The corresponding PrimitiveArrayTypeInfo, or null, if the array is not an array of\n     *     primitives.\n     * @throws InvalidTypesException Thrown, if the given class does not represent an array.\n     */\n    @SuppressWarnings(\"unchecked\")\n    @PublicEvolving\n    public static <X> PrimitiveArrayTypeInfo<X> getInfoFor(Class<X> type) {\n        if (!type.isArray()) {\n            throw new InvalidTypesException(\"The given class is no array.\");\n        }\n\n        // basic type arrays\n        return (PrimitiveArrayTypeInfo<X>) TYPES.get(type);\n    }\n\n    /** Static map from array class to type info. */\n    private static final Map<Class<?>, PrimitiveArrayTypeInfo<?>> TYPES = new HashMap<>();\n\n    // initialization of the static map\n    static {\n        TYPES.put(boolean[].class, BOOLEAN_PRIMITIVE_ARRAY_TYPE_INFO);\n        TYPES.put(byte[].class, BYTE_PRIMITIVE_ARRAY_TYPE_INFO);\n        TYPES.put(short[].class, SHORT_PRIMITIVE_ARRAY_TYPE_INFO);\n        TYPES.put(int[].class, INT_PRIMITIVE_ARRAY_TYPE_INFO);\n        TYPES.put(long[].class, LONG_PRIMITIVE_ARRAY_TYPE_INFO);\n        TYPES.put(float[].class, FLOAT_PRIMITIVE_ARRAY_TYPE_INFO);\n        TYPES.put(double[].class, DOUBLE_PRIMITIVE_ARRAY_TYPE_INFO);","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/typeinfo/PrimitiveArrayTypeInfo.java#L226-L262","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nPrimitiveArrayTypeInfo.getInfoFor(Integer[].class); // boxed, not primitive array\n\n// after\nBasicArrayTypeInfo.getInfoFor(Integer[].class);\n// or for true primitive arrays:\nPrimitiveArrayTypeInfo.getInfoFor(int[].class);","handlingStrategy":"type-guard","validationCode":"Class<?> c = ...;\nif (!c.isArray() || !c.getComponentType().isPrimitive()) {\n    throw new IllegalArgumentException(c + \" is not a primitive array\");\n}\nPrimitiveArrayTypeInfo.getInfoFor(c);","typeGuard":"static boolean isPrimitiveArray(Class<?> c) {\n    return c.isArray() && c.getComponentType().isPrimitive();\n}","tryCatchPattern":"try {\n    return PrimitiveArrayTypeInfo.getInfoFor(type);\n} catch (InvalidTypesException e) {\n    return TypeExtractor.createTypeInfo(type);\n}","preventionTips":["Check isArray() && componentType.isPrimitive() before calling PrimitiveArrayTypeInfo.getInfoFor.","Use TypeExtractor.createTypeInfo for generic dispatch.","Remember Integer[] is BasicArray, int[] is PrimitiveArray."],"tags":["type-information","primitive-array","validation","type-extractor"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}