{"record":{"id":"f1b41f40569a2808","repo":"mybatis/mybatis-3","slug":"the-parameter-alias-cannot-be-null","errorCode":null,"errorMessage":"The parameter alias cannot be null","messagePattern":"The parameter alias cannot be null","errorType":"exception","errorClass":"TypeException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/type/TypeAliasRegistry.java","lineNumber":159,"sourceCode":"      // Skip also inner classes. See issue #6\n      if (!type.isAnonymousClass() && !type.isInterface() && !type.isMemberClass()) {\n        registerAlias(type);\n      }\n    }\n  }\n\n  public void registerAlias(Class<?> type) {\n    String alias = type.getSimpleName();\n    Alias aliasAnnotation = type.getAnnotation(Alias.class);\n    if (aliasAnnotation != null) {\n      alias = aliasAnnotation.value();\n    }\n    registerAlias(alias, type);\n  }\n\n  public void registerAlias(String alias, Class<?> value) {\n    if (alias == null) {\n      throw new TypeException(\"The parameter alias cannot be null\");\n    }\n    // issue #748\n    String key = alias.toLowerCase(Locale.ENGLISH);\n    if (typeAliases.containsKey(key) && typeAliases.get(key) != null && !typeAliases.get(key).equals(value)) {\n      throw new TypeException(\n          \"The alias '\" + alias + \"' is already mapped to the value '\" + typeAliases.get(key).getName() + \"'.\");\n    }\n    typeAliases.put(key, value);\n  }\n\n  public void registerAlias(String alias, String value) {\n    try {\n      registerAlias(alias, Resources.classForName(value));\n    } catch (ClassNotFoundException e) {\n      throw new TypeException(\"Error registering type alias \" + alias + \" for \" + value + \". Cause: \" + e, e);\n    }\n  }\n","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/type/TypeAliasRegistry.java#L141-L177","documentation":"TypeAliasRegistry.registerAlias(alias, value) rejects a null alias with this TypeException because every registered mapping needs a non-null key (lower-cased at registration). It fires before any class resolution happens.","triggerScenarios":"Calling configuration.getTypeAliasRegistry().registerAlias(null, SomeClass.class); or a registration path that derives the alias from an annotation/value that is absent and yields null.","commonSituations":"Programmatic configuration code passing a computed alias that turns out null; wrapping registerAlias in generic bootstrap code that reads aliases from a map/properties file with a missing key.","solutions":["Pass a non-null alias string, or use registerAlias(Class) which defaults the alias to the simple name","Null-check aliases loaded from external config before registering","Annotate the class with @Alias(\"name\") and register by class only"],"exampleFix":"// before\nregistry.registerAlias(aliasFromProps, User.class); // aliasFromProps is null\n\n// after\nregistry.registerAlias(aliasFromProps != null ? aliasFromProps : \"user\", User.class);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(alias, \"alias must not be null\");\nconfiguration.getTypeAliasRegistry().registerAlias(alias, type);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Null-check externally sourced alias strings before registering","Prefer registerAlias(Class) or @Alias annotations over hand-built strings"],"tags":["mybatis","type-alias","registration","null-check"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}