apache/flink · error · NullPointerException

Cannot register null type class.

Error message

Cannot register null type class.

What it means

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.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/common/serialization/SerializerConfigImpl.java:173

        }

        @SuppressWarnings("unchecked")
        Class<? extends Serializer<?>> castedSerializerClass =
                (Class<? extends Serializer<?>>) serializerClass;
        registeredTypesWithKryoSerializerClasses.put(type, castedSerializerClass);
    }

    /**
     * Registers the given type with the serialization stack. If the type is eventually serialized
     * as a POJO, then the type is registered with the POJO serializer. If the type ends up being
     * serialized with Kryo, then it will be registered at Kryo to make sure that only tags are
     * written.
     *
     * @param type The class of the type to register.
     */
    public void registerPojoType(Class<?> type) {
        if (type == null) {
            throw new NullPointerException("Cannot register null type class.");
        }
        registeredPojoTypes.add(type);
    }

    /**
     * Registers the given type with the serialization stack. If the type is eventually serialized
     * as a POJO, then the type is registered with the POJO serializer. If the type ends up being
     * serialized with Kryo, then it will be registered at Kryo to make sure that only tags are
     * written.
     *
     * @param type The class of the type to register.
     */
    public void registerKryoType(Class<?> type) {
        if (type == null) {
            throw new NullPointerException("Cannot register null type class.");
        }
        registeredKryoTypes.add(type);
    }

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Ensure the Class<?> argument is resolved and non-null before registering.
  2. If loading from config, validate the class name string is present and the class loads successfully.

Example fix

// before
Class<?> type = maybeLoadClass(config.getTypeName());
config.registerPojoType(type);

// after
Class<?> type = maybeLoadClass(config.getTypeName());
if (type == null) {
    throw new IllegalStateException("POJO type class not found: " + config.getTypeName());
}
config.registerPojoType(type);
Defensive patterns

Strategy: validation

Validate before calling

if (type == null) {
    throw new IllegalArgumentException("type must not be null");
}
config.registerPojoType(type);

Type guard

import java.util.Objects;
Objects.requireNonNull(type, "type");

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/3a30add03b94982a. Report an issue: GitHub.