Skip to content

Commit 8e8e556

Browse files
committed
Check that the parameter is actually a java array
1 parent bb1db02 commit 8e8e556

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, J
4343
array = (Array)parameter;
4444
}
4545
else {
46+
if (!parameter.getClass().isArray()) {
47+
throw new TypeException("ArrayType Handler requires SQL array or java array parameter and does not support type " + parameter.getClass());
48+
}
4649
Object[] values = (Object[])parameter;
4750
array = ps.getConnection().createArrayOf(jdbcType.name(), values);
4851
}

src/test/java/org/apache/ibatis/type/ArrayTypeHandlerTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import static org.junit.jupiter.api.Assertions.assertEquals;
2525
import static org.junit.jupiter.api.Assertions.assertNull;
26+
import static org.junit.jupiter.api.Assertions.assertThrows;
2627
import static org.mockito.Mockito.verify;
2728
import static org.mockito.Mockito.when;
2829

@@ -46,6 +47,13 @@ public void shouldSetNullParameter() throws Exception {
4647
verify(ps).setNull(1, Types.ARRAY);
4748
}
4849

50+
@Test
51+
public void shouldFailForNonArrayParameter() {
52+
assertThrows(TypeException.class, () -> {
53+
TYPE_HANDLER.setParameter(ps, 1, "unsupported parameter type", null);
54+
});
55+
}
56+
4957
@Override
5058
@Test
5159
public void shouldGetResultFromResultSetByName() throws Exception {

0 commit comments

Comments
 (0)