Skip to content

Commit 6d5db13

Browse files
committed
Only free() the Array if it was created by us. We leave the management of user supplied Arrays to the user.
1 parent ebe6457 commit 6d5db13

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,19 @@ protected void setNullParameter(PreparedStatement ps, int i, JdbcType jdbcType)
4040
public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException {
4141
Array array = null;
4242
if (parameter instanceof Array) {
43-
array = (Array)parameter;
43+
// it's the user's responsibility to properly free() the Array instance
44+
ps.setArray(i, (Array)parameter);
45+
4446
}
4547
else {
4648
if (!parameter.getClass().isArray()) {
4749
throw new TypeException("ArrayType Handler requires SQL array or java array parameter and does not support type " + parameter.getClass());
4850
}
4951
Object[] values = (Object[])parameter;
5052
array = ps.getConnection().createArrayOf(jdbcType.name(), values);
53+
ps.setArray(i, array);
54+
array.free();
5155
}
52-
ps.setArray(i, array);
53-
array.free();
5456
}
5557

5658
@Override

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ class ArrayTypeHandlerTest extends BaseTypeHandlerTest {
3939
public void shouldSetParameter() throws Exception {
4040
TYPE_HANDLER.setParameter(ps, 1, mockArray, null);
4141
verify(ps).setArray(1, mockArray);
42-
verify(mockArray).free();
4342
}
44-
43+
4544
@Test
4645
public void shouldSetNullParameter() throws Exception {
4746
TYPE_HANDLER.setParameter(ps, 1, null, JdbcType.ARRAY);

0 commit comments

Comments
 (0)