Skip to content

Commit 79cd8c2

Browse files
committed
Optimize the code in TypeAliasRegistry
1 parent b83c0f2 commit 79cd8c2

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,8 @@ public <T> Class<T> resolveAlias(String string) {
117117
}
118118
// issue #748
119119
String key = string.toLowerCase(Locale.ENGLISH);
120-
Class<T> value;
121-
if (typeAliases.containsKey(key)) {
122-
value = (Class<T>) typeAliases.get(key);
123-
} else {
120+
Class<T> value = (Class<T>) typeAliases.get(key);
121+
if (value == null) {
124122
value = (Class<T>) Resources.classForName(string);
125123
}
126124
return value;
@@ -161,9 +159,10 @@ public void registerAlias(String alias, Class<?> value) {
161159
}
162160
// issue #748
163161
String key = alias.toLowerCase(Locale.ENGLISH);
164-
if (typeAliases.containsKey(key) && typeAliases.get(key) != null && !typeAliases.get(key).equals(value)) {
162+
Class<?> cls = typeAliases.get(key);
163+
if (cls != null && !cls.equals(value)) {
165164
throw new TypeException(
166-
"The alias '" + alias + "' is already mapped to the value '" + typeAliases.get(key).getName() + "'.");
165+
"The alias '" + alias + "' is already mapped to the value '" + cls.getName() + "'.");
167166
}
168167
typeAliases.put(key, value);
169168
}

0 commit comments

Comments
 (0)