Skip to content

Commit 164a96c

Browse files
committed
Respect the specified type handler
Essentially reverting the condition back to the 3.5.x version. Plus, a minor refactoring (removed an unused method arg).
1 parent bb9c8f1 commit 164a96c

File tree

5 files changed

+8
-9
lines changed

5 files changed

+8
-9
lines changed

src/main/java/org/apache/ibatis/builder/BaseBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,15 @@ protected <T> Class<? extends T> resolveClass(String alias) {
107107

108108
@Deprecated(since = "3.6.0", forRemoval = true)
109109
protected TypeHandler<?> resolveTypeHandler(Class<?> javaType, String typeHandlerAlias) {
110-
return resolveTypeHandler(null, javaType, null, typeHandlerAlias);
110+
return resolveTypeHandler(javaType, null, typeHandlerAlias);
111111
}
112112

113113
@Deprecated(since = "3.6.0", forRemoval = true)
114114
protected TypeHandler<?> resolveTypeHandler(Class<?> javaType, Class<? extends TypeHandler<?>> typeHandlerType) {
115115
return resolveTypeHandler(javaType, null, typeHandlerType);
116116
}
117117

118-
protected TypeHandler<?> resolveTypeHandler(Class<?> parameterType, Type propertyType, JdbcType jdbcType,
119-
String typeHandlerAlias) {
118+
protected TypeHandler<?> resolveTypeHandler(Type propertyType, JdbcType jdbcType, String typeHandlerAlias) {
120119
Class<? extends TypeHandler<?>> typeHandlerType = null;
121120
typeHandlerType = resolveClass(typeHandlerAlias);
122121
if (typeHandlerType != null && !TypeHandler.class.isAssignableFrom(typeHandlerType)) {

src/main/java/org/apache/ibatis/builder/ParameterMappingTokenHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ private ParameterMapping buildParameterMapping(String content) {
9595
if (genericType == null) {
9696
genericType = javaType;
9797
}
98-
if ((typeHandler == null || typeHandlerAlias != null) && genericType != null && genericType != Object.class) {
99-
typeHandler = resolveTypeHandler(parameterType, genericType, jdbcType, typeHandlerAlias);
98+
if (typeHandler == null || typeHandlerAlias != null) {
99+
typeHandler = resolveTypeHandler(genericType, jdbcType, typeHandlerAlias);
100100
}
101101
builder.typeHandler(typeHandler);
102102

src/test/java/org/apache/ibatis/builder/XmlMapperBuilderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void resolveTypeHandlerTypeHandlerAliasIsNull() {
153153
{
154154
}
155155
};
156-
TypeHandler<?> typeHandler = builder.resolveTypeHandler(String.class, null, null, (String) null);
156+
TypeHandler<?> typeHandler = builder.resolveTypeHandler(null, null, (String) null);
157157
assertThat(typeHandler).isNull();
158158
}
159159

@@ -163,7 +163,7 @@ void resolveTypeHandlerNoAssignable() {
163163
{
164164
}
165165
};
166-
when(() -> builder.resolveTypeHandler(String.class, null, null, "integer"));
166+
when(() -> builder.resolveTypeHandler(null, null, "integer"));
167167
then(caughtException()).isInstanceOf(BuilderException.class).hasMessage(
168168
"Type java.lang.Integer is not a valid TypeHandler because it does not implement TypeHandler interface");
169169
}

src/test/java/org/apache/ibatis/submitted/language/VelocitySqlSourceBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private ParameterMapping buildParameterMapping(String content) {
134134
}
135135
}
136136
if (typeHandlerAlias != null) {
137-
builder.typeHandler(resolveTypeHandler(javaType, propertyType, jdbcType, typeHandlerAlias));
137+
builder.typeHandler(resolveTypeHandler(propertyType, jdbcType, typeHandlerAlias));
138138
}
139139
return builder.build();
140140
}

src/test/java/org/apache/ibatis/submitted/typebasedtypehandlerresolution/LocallySpecifiedTypeHandlerResolutionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ void specifyHandlerInXmlParameterWithoutParameterType() {
309309
// There is no way to obtain info about type parameters.
310310
assertThatExceptionOfType(PersistenceException.class).isThrownBy(() -> sqlSession.insert(
311311
"org.apache.ibatis.submitted.typebasedtypehandlerresolution.LocallySpecifiedHandlerMapper.insertXmlWithoutParameterType",
312-
user)).withMessageContaining("FuzzyBean cannot be cast to class java.lang.String");
312+
user)).withMessageContaining("Unknown rawType : class java.lang.Object");
313313
}
314314
}
315315
}

0 commit comments

Comments
 (0)