{"record":{"id":"90a68612c3e1a196","repo":"apache/flink","slug":"the-elements-in-the-collection-are-not-all-subclas-90a686","errorCode":null,"errorMessage":"The elements in the collection are not all subclasses of {viewedAs.getCanonicalName()}","messagePattern":"The elements in the collection are not all subclasses of (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-connectors/flink-connector-datagen/src/main/java/org/apache/flink/connector/datagen/functions/IndexLookupGeneratorFunction.java","lineNumber":120,"sourceCode":"        return lookupMap.get(index);\n    }\n\n    /**\n     * Verifies that all elements in the iterable are non-null, and are of the given class, or a\n     * subclass thereof.\n     *\n     * @param elements The iterable to check.\n     * @param viewedAs The class to which the elements must be assignable to.\n     */\n    private void checkIterable(Iterable<OUT> elements, Class<?> viewedAs) {\n        for (OUT elem : elements) {\n            numElements++;\n            if (elem == null) {\n                throw new IllegalArgumentException(\"The collection contains a null element\");\n            }\n\n            if (!viewedAs.isAssignableFrom(elem.getClass())) {\n                throw new IllegalArgumentException(\n                        \"The elements in the collection are not all subclasses of \"\n                                + viewedAs.getCanonicalName());\n            }\n        }\n    }\n\n    private void serializeElements(Iterable<OUT> elements) throws IOException {\n        Preconditions.checkState(serializer != null, \"serializer not set\");\n        LOG.info(\"Serializing elements using  {}\", serializer);\n        ByteArrayOutputStream baos = new ByteArrayOutputStream();\n        DataOutputViewStreamWrapper wrapper = new DataOutputViewStreamWrapper(baos);\n\n        try {\n            for (OUT element : elements) {\n                serializer.serialize(element, wrapper);\n            }\n        } catch (Exception e) {\n            throw new IOException(\"Serializing the source elements failed: \" + e.getMessage(), e);","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-connectors/flink-connector-datagen/src/main/java/org/apache/flink/connector/datagen/functions/IndexLookupGeneratorFunction.java#L102-L138","documentation":"Thrown by checkIterable in IndexLookupGeneratorFunction when an element's runtime class is not assignable to the class derived from the provided TypeInformation. The message includes the canonical name of the expected type, helping pinpoint the type mismatch.","triggerScenarios":"Passing a TypeInformation for one class but including elements of an incompatible runtime type in the collection; heterogeneous raw-type list pollution at construction time.","commonSituations":"Type erasure accepting a heterogeneous list; accidental type widening; TypeInformation auto-inference resolving to the wrong class.","solutions":["Ensure all elements match the declared TypeInformation's type class.","Use Flink's Types utility to specify TypeInformation explicitly and unambiguously.","Inspect the canonical name in the error message to identify the expected type, then fix the mismatched element."],"exampleFix":"// before: expected Long but list contains a String\nList<Object> mixed = Arrays.asList(1L, \"two\", 3L);\nnew IndexLookupGeneratorFunction<>(Types.LONG, mixed);\n\n// after: use consistent types\nList<Long> elements = Arrays.asList(1L, 2L, 3L);\nnew IndexLookupGeneratorFunction<>(Types.LONG, elements);","handlingStrategy":"validation","validationCode":"// Verify type assignability before constructing\nClass<?> expected = typeInfo.getTypeClass();\nfor (OUT elem : elements) {\n    if (elem == null || !expected.isAssignableFrom(elem.getClass())) {\n        throw new IllegalArgumentException(\"Type mismatch: \" + elem);\n    }\n}\nnew IndexLookupGeneratorFunction<>(typeInfo, elements);","typeGuard":"static <T> boolean allAssignableToType(Iterable<T> elements, TypeInformation<?> typeInfo) {\n    Class<?> expected = typeInfo.getTypeClass();\n    for (T elem : elements) {\n        if (elem == null || !expected.isAssignableFrom(elem.getClass())) return false;\n    }\n    return true;\n}","tryCatchPattern":null,"preventionTips":["Use strongly typed collections.","Specify TypeInformation explicitly with Flink's Types utility.","Validate element types before construction."],"tags":["datagen","type-system","validation","type-mismatch","index-lookup"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}