{"record":{"id":"3a30add03b94982a","repo":"apache/flink","slug":"cannot-register-null-type-class","errorCode":null,"errorMessage":"Cannot register null type class.","messagePattern":"Cannot register null type class\\.","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/serialization/SerializerConfigImpl.java","lineNumber":173,"sourceCode":"        }\n\n        @SuppressWarnings(\"unchecked\")\n        Class<? extends Serializer<?>> castedSerializerClass =\n                (Class<? extends Serializer<?>>) serializerClass;\n        registeredTypesWithKryoSerializerClasses.put(type, castedSerializerClass);\n    }\n\n    /**\n     * Registers the given type with the serialization stack. If the type is eventually serialized\n     * as a POJO, then the type is registered with the POJO serializer. If the type ends up being\n     * serialized with Kryo, then it will be registered at Kryo to make sure that only tags are\n     * written.\n     *\n     * @param type The class of the type to register.\n     */\n    public void registerPojoType(Class<?> type) {\n        if (type == null) {\n            throw new NullPointerException(\"Cannot register null type class.\");\n        }\n        registeredPojoTypes.add(type);\n    }\n\n    /**\n     * Registers the given type with the serialization stack. If the type is eventually serialized\n     * as a POJO, then the type is registered with the POJO serializer. If the type ends up being\n     * serialized with Kryo, then it will be registered at Kryo to make sure that only tags are\n     * written.\n     *\n     * @param type The class of the type to register.\n     */\n    public void registerKryoType(Class<?> type) {\n        if (type == null) {\n            throw new NullPointerException(\"Cannot register null type class.\");\n        }\n        registeredKryoTypes.add(type);\n    }","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/serialization/SerializerConfigImpl.java#L155-L191","documentation":"Thrown by registerPojoType(Class<?> type) when the type argument is null. This method registers a type so that, if it ends up serialized as a POJO, it uses the POJO serializer with stable tags. A null class has no meaningful registration target and is rejected before adding to the registeredPojoTypes set.","triggerScenarios":"Calling registerPojoType(null) directly, or passing a class that was loaded dynamically but came back null. Typically the result of a missing or unresolvable class name in configuration.","commonSituations":"Configuration-driven POJO type registration where a type name string is empty or the class is not on the classpath; programmatic registration with a computed class that is null.","solutions":["Ensure the Class<?> argument is resolved and non-null before registering.","If loading from config, validate the class name string is present and the class loads successfully."],"exampleFix":"// before\nClass<?> type = maybeLoadClass(config.getTypeName());\nconfig.registerPojoType(type);\n\n// after\nClass<?> type = maybeLoadClass(config.getTypeName());\nif (type == null) {\n    throw new IllegalStateException(\"POJO type class not found: \" + config.getTypeName());\n}\nconfig.registerPojoType(type);","handlingStrategy":"validation","validationCode":"if (type == null) {\n    throw new IllegalArgumentException(\"type must not be null\");\n}\nconfig.registerPojoType(type);","typeGuard":"import java.util.Objects;\nObjects.requireNonNull(type, \"type\");","tryCatchPattern":null,"preventionTips":["Resolve and validate type classes from config before registering.","Test that all configured class names resolve at startup."],"tags":["serialization","pojo","null-check","configuration"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}