{"record":{"id":"1e8ef73c0c45a0b6","repo":"mybatis/mybatis-3","slug":"type-argument-cannot-be-null-1e8ef7","errorCode":null,"errorMessage":"Type argument cannot be null","messagePattern":"Type argument cannot be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/type/EnumTypeHandler.java","lineNumber":32,"sourceCode":" *    limitations under the License.\n */\npackage org.apache.ibatis.type;\n\nimport java.sql.CallableStatement;\nimport java.sql.PreparedStatement;\nimport java.sql.ResultSet;\nimport java.sql.SQLException;\n\n/**\n * @author Clinton Begin\n */\npublic class EnumTypeHandler<E extends Enum<E>> extends BaseTypeHandler<E> {\n\n  private final Class<E> type;\n\n  public EnumTypeHandler(Class<E> type) {\n    if (type == null) {\n      throw new IllegalArgumentException(\"Type argument cannot be null\");\n    }\n    this.type = type;\n  }\n\n  @Override\n  public void setNonNullParameter(PreparedStatement ps, int i, E parameter, JdbcType jdbcType) throws SQLException {\n    if (jdbcType == null) {\n      ps.setString(i, parameter.name());\n    } else {\n      ps.setObject(i, parameter.name(), jdbcType.TYPE_CODE); // see r3589\n    }\n  }\n\n  @Override\n  public E getNullableResult(ResultSet rs, String columnName) throws SQLException {\n    String s = rs.getString(columnName);\n    return s == null ? null : Enum.valueOf(type, s);\n  }","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/type/EnumTypeHandler.java#L14-L50","documentation":"EnumTypeHandler (name-based enum mapping) stores the enum Class to convert names back to constants. Constructing it with a null Class throws this IllegalArgumentException from the constructor — the handler cannot operate on an unknown type.","triggerScenarios":"new EnumTypeHandler<>(null); or a <typeHandler handler=\"...EnumTypeHandler\"/> registration without javaType, causing TypeHandlerRegistry to instantiate it with a null type; unresolved java types on enum properties.","commonSituations":"Registering EnumTypeHandler in XML without the javaType attribute; a parameter or property whose generic type was erased so MyBatis could not infer the enum class.","solutions":["Add javaType to the registration: <typeHandler handler=\"...EnumTypeHandler\" javaType=\"com.example.MyEnum\"/>","Give the mapper property an explicit javaType (#{status,javaType=com.example.MyEnum})","When constructing manually, pass the non-null enum class"],"exampleFix":"// before\nnew EnumTypeHandler<>(null);\n\n// after\nnew EnumTypeHandler<>(Status.class);","handlingStrategy":"validation","validationCode":"if (enumClass == null) throw new IllegalArgumentException(\"enumClass required for EnumTypeHandler\");\nreturn new EnumTypeHandler<>(enumClass);","typeGuard":"static <E extends Enum<E>> EnumTypeHandler<E> safeNameHandler(Class<E> type) {\n  return type == null ? null : new EnumTypeHandler<>(type);\n}","tryCatchPattern":null,"preventionTips":["Always specify javaType when registering EnumTypeHandler","At startup, resolve every alias used in mappers to catch missing types early"],"tags":["mybatis","enum","type-handler","configuration"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}