Skip to content

Commit fb2a6e9

Browse files
committed
Optimize the code in TypeAliasRegistry
1 parent e68216b commit fb2a6e9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main/java/org/apache/ibatis/type/TypeAliasRegistry.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,14 @@ public void registerAlias(String alias, Class<?> value) {
161161
}
162162
// issue #748
163163
String key = alias.toLowerCase(Locale.ENGLISH);
164-
if (typeAliases.containsKey(key) && typeAliases.get(key) != null && !typeAliases.get(key).equals(value)) {
165-
throw new TypeException(
166-
"The alias '" + alias + "' is already mapped to the value '" + typeAliases.get(key).getName() + "'.");
164+
Class<?> cls = typeAliases.get(key);
165+
if (cls != null) {
166+
if (!cls.equals(value)) {
167+
throw new TypeException("The alias '" + alias + "' is already mapped to the value '" + cls.getName() + "'.");
168+
}
169+
} else {
170+
typeAliases.put(key, value);
167171
}
168-
typeAliases.put(key, value);
169172
}
170173

171174
public void registerAlias(String alias, String value) {

0 commit comments

Comments
 (0)