{"record":{"id":"b39158d22f16e797","repo":"apache/flink","slug":"serializerfactory-has-not-been-initialized-from-co","errorCode":null,"errorMessage":"SerializerFactory has not been initialized from configuration.","messagePattern":"SerializerFactory has not been initialized from configuration\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/RuntimeSerializerFactory.java","lineNumber":85,"sourceCode":"            throw new NullPointerException();\n        }\n\n        try {\n            this.clazz = InstantiationUtil.readObjectFromConfig(config, CONFIG_KEY_CLASS, cl);\n            this.serializer = InstantiationUtil.readObjectFromConfig(config, CONFIG_KEY_SER, cl);\n        } catch (ClassNotFoundException e) {\n            throw e;\n        } catch (Exception e) {\n            throw new RuntimeException(\"Could not load deserializer from the configuration.\", e);\n        }\n    }\n\n    @Override\n    public TypeSerializer<T> getSerializer() {\n        if (this.serializer != null) {\n            return this.serializer.duplicate();\n        } else {\n            throw new RuntimeException(\n                    \"SerializerFactory has not been initialized from configuration.\");\n        }\n    }\n\n    @Override\n    public Class<T> getDataType() {\n        return clazz;\n    }\n\n    // --------------------------------------------------------------------------------------------\n\n    @Override\n    public int hashCode() {\n        return clazz.hashCode() ^ serializer.hashCode();\n    }\n\n    @Override\n    public boolean equals(Object obj) {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/RuntimeSerializerFactory.java#L67-L103","documentation":"RuntimeSerializerFactory.getSerializer throws this when its serializer field is null, meaning the factory was never initialized via readParametersFromConfig (or that read failed). It is a lifecycle-ordering bug in the caller: the factory only yields a serializer after being populated from a Configuration written on the job-submission side.","triggerScenarios":"new RuntimeSerializerFactory<>() (no-arg) followed directly by getSerializer(); or writeParametersToConfig failing on the sender so the receiver's readParametersFromConfig never ran; or readParametersFromConfig throwing (null config/cl -> NPE; deserialization failure) and getSerializer being called regardless.","commonSituations":"Utility code or tests reusing a factory instance across a failure boundary. Framework glue that constructs the factory reflectively but skips the read step. Calling getDataType()/getSerializer() on the sender-side instance after only using it as a template (sender instance actually keeps fields, but a no-arg constructed one does not).","solutions":["Follow the write->read->get lifecycle: construct with the serializer, writeParametersToConfig on the client; on the cluster construct no-arg and call readParametersFromConfig(config, userClassloader) before getSerializer().","If readParametersFromConfig throws, abort and surface that exception; never fall through to getSerializer().","In tests, always round-trip through a Configuration rather than using a bare factory."],"exampleFix":"// before\nRuntimeSerializerFactory<String> f = new RuntimeSerializerFactory<>();\nTypeSerializer<String> s = f.getSerializer(); // NPE-guarded -> RuntimeException 685\n\n// after\nConfiguration cfg = new Configuration();\nnew RuntimeSerializerFactory<>(String.class, new StringValueSerializer()).writeParametersToConfig(cfg);\nRuntimeSerializerFactory<String> f2 = new RuntimeSerializerFactory<>();\nf2.readParametersFromConfig(cfg, Thread.currentThread().getContextClassLoader());\nTypeSerializer<String> s = f2.getSerializer();","handlingStrategy":"validation","validationCode":"public static <T> TypeSerializer<T> initializedSerializer(\n        RuntimeSerializerFactory<T> f, Configuration cfg, ClassLoader cl) throws Exception {\n    f.readParametersFromConfig(cfg, cl);\n    return f.getSerializer(); // getSerializer only after successful read\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call getSerializer() before a successful readParametersFromConfig on a no-arg factory.","Short-circuit the whole setup when readParametersFromConfig throws instead of continuing.","Wrap factory usage in one helper that enforces the lifecycle."],"tags":["lifecycle","type-serializer","initialization","misuse"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}