baomidou/mybatis-plus · error · IllegalArgumentException

Type argument cannot be null

Error message

Type argument cannot be null

What it means

CompositeEnumTypeHandler was constructed with a null enum class. This handler is created by the TypeHandlerRegistry for enum-typed properties; a null type argument means the registry could not determine the Java type for the property being mapped (e.g. an unresolvable javaType).

Source

Thrown at mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/handlers/CompositeEnumTypeHandler.java:45

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author miemie
 * @since 2022-03-07
 */
public class CompositeEnumTypeHandler<E extends Enum<E>> implements TypeHandler<E> {

    private static final Map<Class<?>, Boolean> MP_ENUM_CACHE = new ConcurrentHashMap<>();
    private static Class<? extends TypeHandler> defaultEnumTypeHandler = EnumTypeHandler.class;
    private final TypeHandler<E> delegate;

    public CompositeEnumTypeHandler(Class<E> enumClassType) {
        if (enumClassType == null) {
            throw new IllegalArgumentException("Type argument cannot be null");
        }
        if (CollectionUtils.computeIfAbsent(MP_ENUM_CACHE, enumClassType, EnumUtils::isMpEnums)) {
            delegate = new MybatisEnumTypeHandler<>(enumClassType);
        } else {
            delegate = getInstance(enumClassType, defaultEnumTypeHandler);
        }
    }

    public static void setDefaultEnumTypeHandler(Class<? extends TypeHandler> defaultEnumTypeHandler) {
        if (defaultEnumTypeHandler != null && !MybatisEnumTypeHandler.class.isAssignableFrom(defaultEnumTypeHandler)) {
            CompositeEnumTypeHandler.defaultEnumTypeHandler = defaultEnumTypeHandler;
        }
    }

    @Override
    public void setParameter(PreparedStatement ps, int i, E parameter, JdbcType jdbcType) throws SQLException {
        delegate.setParameter(ps, i, parameter, jdbcType);
    }

View on GitHub (pinned to bf67d90747)

Solutions

  1. Check the resultMap/parameterMap javaType attributes in the mapper named in the stack trace and fix unresolvable class names
  2. Declare the concrete enum type on the mapper method parameter or entity field so the registry knows the type
  3. Verify the enum class is on the classpath and not shaded/renamed

Example fix

<!-- before -->
<result property="status" javaType="com.exmaple.Status"/>
<!-- after -->
<result property="status" javaType="com.example.Status"/>
Defensive patterns

Strategy: validation

Validate before calling

// Ensure every enum property has a concrete javaType before the session is built
if (methodParamOrFieldType == null || !Enum.class.isAssignableFrom(it)) {
    throw new IllegalStateException("Enum property must resolve to a concrete enum type");
}

Prevention

When it happens

Trigger: A mapper XML/resultMap/parameterMap references an enum type that resolves to null (typo'd javaType FQCN, or a generic property whose type cannot be inferred), causing the registry to instantiate CompositeEnumTypeHandler(null).

Common situations: Setting default-enum-type-handler to CompositeEnumTypeHandler in configuration while some statement has an unresolvable javaType; using raw/generic wrapper types where reflection cannot determine the enum; misconfigured mybatis-plus.type-enums-package setups in older versions.

Related errors


AI-assisted analysis of baomidou/mybatis-plus@bf67d90747 (2026-08-14). Data as JSON: /api/errors/43786a38f9d47d14. Report an issue: GitHub.