baomidou/mybatis-plus · error · IllegalArgumentException
Type argument cannot be null
Error message
Type argument cannot be null
What it means
MybatisEnumTypeHandler (used for enums with @EnumValue/IEnum support) was constructed with a null enum class. Unlike error 28, this occurs when the handler is instantiated directly or via a registry path that passes no resolvable enum type.
Source
Thrown at mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/handlers/MybatisEnumTypeHandler.java:46
/**
* 自定义枚举属性转换器
*
* @author hubin
* @since 2017-10-11
*/
public final class MybatisEnumTypeHandler<E extends Enum<E>> extends BaseTypeHandler<E> {
private final EnumMetadata metadata;
/**
* 创建枚举类型处理器。
*
* @param enumClassType 枚举类型
*/
public MybatisEnumTypeHandler(Class<E> enumClassType) {
if (enumClassType == null) {
throw new IllegalArgumentException("Type argument cannot be null");
}
this.metadata = EnumUtils.metadata(enumClassType);
}
/**
* 查找标记标记EnumValue字段。
*
* @param clazz class
* @return EnumValue字段
* @since 3.3.1
*/
public static Optional<String> findEnumValueFieldName(Class<?> clazz) {
return EnumUtils.findEnumValueFieldName(clazz);
}
@SuppressWarnings("Duplicates")
@Override
public void setNonNullParameter(PreparedStatement ps, int i, E parameter, JdbcType jdbcType)View on GitHub (pinned to bf67d90747)
Solutions
- Use CompositeEnumTypeHandler as the default enum handler; MybatisEnumTypeHandler is meant to be created with a concrete enum class
- In XML, always pair typeHandler="...MybatisEnumTypeHandler" with an explicit javaType="com.example.MyEnum"
- Fix custom registration code to pass the resolved enum class, never null
Example fix
<!-- before --> <result property="status" typeHandler="org.apache.ibatis.type.MybatisEnumTypeHandler"/> <!-- after --> <result property="status" javaType="com.example.Status" typeHandler="com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler"/>
Defensive patterns
Strategy: validation
Validate before calling
if (enumClass == null || !enumClass.isEnum()) {
throw new IllegalStateException("MybatisEnumTypeHandler requires a concrete enum class");
}
new MyEnumTypeHandler<>(enumClass); Prevention
- Register CompositeEnumTypeHandler as default; never MybatisEnumTypeHandler directly
- Pair typeHandler= in XML with an explicit javaType
- Cover enum mapping with an H2-backed integration test per enum
When it happens
Trigger: Registering MybatisEnumTypeHandler directly as the default enum handler (e.g. typeHandlerRegistry or configuration setting) in a context where the Java type is unknown; explicit new MybatisEnumTypeHandler<>(null); mapper statements whose javaType is missing and unresolvable for an enum property.
Common situations: Setting mybatis-plus default-enum-type-handler to MybatisEnumTypeHandler instead of CompositeEnumTypeHandler; inline typeHandler= references in XML without a javaType on the property; custom registration code passing a null class.
Related errors
- Type argument cannot be null
- Failed invoking constructor for handler %s
- Unable to find a usable constructor for %s
- Type argument cannot be null
- Type argument must be an enum: {}
AI-assisted analysis of baomidou/mybatis-plus@bf67d90747 (2026-08-14).
Data as JSON: /api/errors/2eba08e4d6d5d50c.
Report an issue: GitHub.