Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/main/java/org/apache/ibatis/binding/MapperMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,22 @@ private <E> Object convertToDeclaredCollection(Configuration config, List<E> lis
}

@SuppressWarnings("unchecked")
private <E> E[] convertToArray(List<E> list) {
E[] array = (E[]) Array.newInstance(method.getReturnType().getComponentType(), list.size());
array = list.toArray(array);
return array;
private <E> Object convertToArray(List<E> list) {

Class<?> arrayComponentType = method.getReturnType().getComponentType();

Object array = Array.newInstance(arrayComponentType, list.size());
Object value;
if (arrayComponentType.isPrimitive()) {
for (int i = 0; i < list.size(); i++) {
Array.set(array, i, list.get(i));
}
value = array;
} else {
value = list.toArray((Object[])array);
}

return value;
}

private <K, V> Map<K, V> executeForMap(SqlSession sqlSession, Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,10 @@ public void shouldGetSimpleTypeArray() {
}
}

@Test(expected = ClassCastException.class)
@Test
public void shouldGetPrimitiveArray() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
// Throwing an exception is the expected behavior
// until #555 is fixed
Mapper mapper = sqlSession.getMapper(Mapper.class);
int[] ids = mapper.getUserIdsPrimitive();
assertEquals(1, ids[0]);
Expand Down