{"record":{"id":"e1a1e383cda829d4","repo":"apache/flink","slug":"e-getmessage-e1a1e3","errorCode":null,"errorMessage":"{e.getMessage()}","messagePattern":"\\{e\\.getMessage\\(\\)\\}","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-connectors/flink-connector-datagen/src/main/java/org/apache/flink/connector/datagen/functions/FromElementsGeneratorFunction.java","lineNumber":164,"sourceCode":"    // For backward compatibility: Supports legacy usage of\n    // StreamExecutionEnvironment#fromElements() which lacked type information and relied on the\n    // returns() method. See FLINK-21386 for details.\n    @Override\n    public void setOutputType(TypeInformation<OUT> outTypeInfo, ExecutionConfig executionConfig) {\n        Preconditions.checkState(\n                elements != null,\n                \"The output type should've been specified before shipping the graph to the cluster\");\n        checkIterable(elements, outTypeInfo.getTypeClass());\n        TypeSerializer<OUT> newSerializer =\n                outTypeInfo.createSerializer(executionConfig.getSerializerConfig());\n        if (Objects.equals(serializer, newSerializer)) {\n            return;\n        }\n        serializer = newSerializer;\n        try {\n            serializeElements(elements);\n        } catch (IOException e) {\n            throw new RuntimeException(e.getMessage(), e);\n        }\n    }\n\n    private void trySerialize(Iterable<OUT> elements) {\n        try {\n            serializeElements(elements);\n        } catch (IOException e) {\n            throw new RuntimeException(e.getMessage(), e);\n        }\n    }\n\n    // ------------------------------------------------------------------------\n    //  Utilities\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.","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-connectors/flink-connector-datagen/src/main/java/org/apache/flink/connector/datagen/functions/FromElementsGeneratorFunction.java#L146-L182","documentation":"In setOutputType (and the private trySerialize), if serializeElements throws IOException the code wraps it in a RuntimeException carrying only e.getMessage() and the cause. This happens when the framework sets the output type after construction and re-serialization under the resolved serializer fails for the given elements.","triggerScenarios":"OutputTypeConfigurable#setOutputType is invoked by the framework with the inferred TypeInformation, the resolved serializer differs from the one used at construction, and re-serializing the elements under the new serializer fails.","commonSituations":"The element type inferred by Flink differs from what was passed to the constructor, so re-serialization under the new serializer rejects an element; custom types whose serializer behavior depends on config only available at setOutputType time.","solutions":["Construct FromElementsGeneratorFunction with the same TypeInformation the framework will infer (use explicit returns()/TypeInformation to avoid divergence).","Ensure all elements are serializable under any serializer the resolved TypeInformation would produce.","Inspect the wrapped IOException cause for the failing element/field.","Avoid passing an ExecutionConfig at construction that differs from the runtime config, which can yield a different serializer."],"exampleFix":"// before: constructor uses one type, framework infers another -> re-serialize fails\nnew FromElementsGeneratorFunction<>(Types.GENERIC(Object.class), myPojos);\n// after: declare the concrete type so setOutputType keeps the same serializer\nnew FromElementsGeneratorFunction<>(Types.POJO(MyPojo.class), myPojos);","handlingStrategy":"validation","validationCode":"// Use the same TypeInformation the framework will infer to avoid a serializer swap:\nTypeInformation<OUT> ti = TypeInformation.of(MyPojo.class);\nFromElementsGeneratorFunction<OUT> fn = new FromElementsGeneratorFunction<>(ti, elements);\n// Ensure setOutputType will resolve to the same serializer:\nOUT sample = elements.iterator().next();\nTypeSerializer<OUT> s1 = ti.createSerializer(config.getSerializerConfig());\ns1.serialize(sample, new DataOutputViewStreamWrapper(new ByteArrayOutputStream())); // must not throw","typeGuard":null,"tryCatchPattern":"try {\n    ((OutputTypeConfigurable<OUT>) fn).setOutputType(inferredType, config);\n} catch (RuntimeException e) {\n    Throwable c = e.getCause() != null ? e.getCause() : e;\n    throw new RuntimeException(\"Re-serialization under inferred type failed: \" + inferredType, c);\n}","preventionTips":["Construct with the concrete TypeInformation the framework will infer.","Use explicit returns()/TypeInformation to prevent type inference divergence.","Ensure all elements serialize under any serializer the resolved type produces."],"tags":["serialization","type-information","from-elements","output-type","flink"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}