Skip to content

Commit 8c98dff

Browse files
kazuki43zooh3adache
authored andcommitted
Polishing #1240
1 parent 2bc4ce2 commit 8c98dff

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,11 @@ private boolean allowedConstructor(final Constructor<?> constructor, final List<
698698
if (parameterTypes.length != classNames.size()) return false;
699699
for (int i = 0; i < parameterTypes.length; i++) {
700700
final Class<?> parameterType = parameterTypes[i];
701-
final String className = classNames.get(i);
702-
if (parameterType.isPrimitive() && !primitiveTypes.getWrapper(parameterType).getName().equals(className)) {
703-
return false;
704-
} else if (!parameterType.isPrimitive() && !parameterType.isAssignableFrom(toClassForName(className))) {
701+
final Class<?> resultSetType = toClassForName(classNames.get(i));
702+
boolean matches = parameterType.isPrimitive()
703+
? primitiveTypes.matchesWithWrapperType(parameterType, resultSetType)
704+
: parameterType.isAssignableFrom(resultSetType);
705+
if (!matches) {
705706
return false;
706707
}
707708
}

src/main/java/org/apache/ibatis/executor/resultset/PrimitiveTypes.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,6 +46,18 @@ public Class<?> getWrapper(final Class<?> primitiveType) {
4646
return primitiveToWrappers.get(primitiveType);
4747
}
4848

49+
/**
50+
* Whether or not a specifying type matches with the wrapper type corresponding a primitive type.
51+
*
52+
* @param primitiveType a primitive type
53+
* @param targetType type of validating target
54+
* @return if return {@code true}, a wrapper type is matched.
55+
* @since 3.5.0
56+
*/
57+
public boolean matchesWithWrapperType(final Class<?> primitiveType, final Class<?> targetType) {
58+
return targetType == getWrapper(primitiveType);
59+
}
60+
4961
public Class<?> getPrimitive(final Class<?> wrapperType) {
5062
return wrappersToPrimitives.get(wrapperType);
5163
}

src/test/java/org/apache/ibatis/autoconstructor/WrapperSubject.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class WrapperSubject {
2525
private final int weight;
2626
private final Timestamp dt;
2727

28+
public WrapperSubject(final int id, final String name, final int age, final Short height, final Short weight, Timestamp dt) {
29+
throw new IllegalStateException("This constructor must not be called because type mismatch.");
30+
}
31+
2832
public WrapperSubject(final int id, final String name, final int age, final Integer height, final Integer weight, Timestamp dt) {
2933
this.id = id;
3034
this.name = name;

0 commit comments

Comments
 (0)