Skip to content

Commit

Permalink
Optimize the code in TypeAliasRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
kang-hl committed Mar 8, 2023
1 parent b83c0f2 commit 79cd8c2
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/main/java/org/apache/ibatis/type/TypeAliasRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ public <T> Class<T> resolveAlias(String string) {
}
// issue #748
String key = string.toLowerCase(Locale.ENGLISH);
Class<T> value;
if (typeAliases.containsKey(key)) {
value = (Class<T>) typeAliases.get(key);
} else {
Class<T> value = (Class<T>) typeAliases.get(key);
if (value == null) {
value = (Class<T>) Resources.classForName(string);
}
return value;
Expand Down Expand Up @@ -161,9 +159,10 @@ public void registerAlias(String alias, Class<?> value) {
}
// issue #748
String key = alias.toLowerCase(Locale.ENGLISH);
if (typeAliases.containsKey(key) && typeAliases.get(key) != null && !typeAliases.get(key).equals(value)) {
Class<?> cls = typeAliases.get(key);
if (cls != null && !cls.equals(value)) {
throw new TypeException(
"The alias '" + alias + "' is already mapped to the value '" + typeAliases.get(key).getName() + "'.");
"The alias '" + alias + "' is already mapped to the value '" + cls.getName() + "'.");
}
typeAliases.put(key, value);
}
Expand Down

0 comments on commit 79cd8c2

Please sign in to comment.