Skip to content

Commit 03e69d2

Browse files
chenyuzhi459julianhyde
authored andcommitted
[CALCITE-4573] NullPointerException while fetching from a column of type ARRAY
Close #141
1 parent 8ec334f commit 03e69d2

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ public void close() {
153153
this.cursor = null;
154154
cursor.close();
155155
}
156-
statement.onResultSetClose(this);
156+
if (statement != null) {
157+
statement.onResultSetClose(this);
158+
}
157159
}
158160

159161
/** Sets the flag to indicate that cancel has been requested.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.calcite.avatica;
18+
19+
import org.apache.calcite.avatica.Meta.Signature;
20+
import org.apache.calcite.avatica.util.DateTimeUtils;
21+
22+
import org.junit.runner.RunWith;
23+
import org.junit.runners.Parameterized;
24+
import org.junit.runners.Parameterized.Parameters;
25+
26+
import java.lang.reflect.Method;
27+
import java.sql.ResultSet;
28+
import java.util.Collections;
29+
30+
import static org.junit.Assert.assertTrue;
31+
32+
/**
33+
* Tests for {@code AvaticaResultSet} relative to close behavior
34+
*/
35+
@RunWith(Parameterized.class)
36+
public class AvaticaClosedResultSetWithNullStatementTest extends AvaticaClosedTestBase<ResultSet> {
37+
// Mapping between Connection method and the verifier to check close behavior
38+
private static MethodVerifier methodVerifier(Method method) {
39+
String name = method.getName();
40+
// All update methods are not supported yet
41+
if (name.startsWith("update")) {
42+
return ASSERT_UNSUPPORTED;
43+
}
44+
45+
switch (name) {
46+
case "absolute":
47+
case "afterLast":
48+
case "beforeFirst":
49+
case "cancelRowUpdates":
50+
case "deleteRow":
51+
case "first":
52+
case "getCursorName":
53+
case "getRowId":
54+
case "insertRow":
55+
case "isLast":
56+
case "last":
57+
case "moveToCurrentRow":
58+
case "moveToInsertRow":
59+
case "previous":
60+
case "refreshRow":
61+
case "relative":
62+
return ASSERT_UNSUPPORTED;
63+
64+
default:
65+
return ASSERT_CLOSED;
66+
}
67+
};
68+
69+
@Parameters(name = "{index}: {0}")
70+
public static Iterable<? extends Object[]> getParameters() {
71+
return getMethodsToTest(ResultSet.class, AvaticaResultSet.class, METHOD_FILTER,
72+
AvaticaClosedResultSetWithNullStatementTest::methodVerifier);
73+
}
74+
75+
public AvaticaClosedResultSetWithNullStatementTest(Method method, MethodVerifier verifier) {
76+
super(method, verifier);
77+
}
78+
79+
@Override protected ResultSet newInstance() throws Exception {
80+
Signature signature = new Signature(Collections.emptyList(), "", Collections.emptyList(),
81+
Collections.emptyMap(), null, Meta.StatementType.SELECT);
82+
AvaticaResultSet resultSet = new AvaticaResultSet(null, new QueryState(""), signature,
83+
null, DateTimeUtils.UTC_ZONE, null);
84+
resultSet.close();
85+
assertTrue("Resultset is not closed", resultSet.isClosed());
86+
87+
return resultSet;
88+
}
89+
}
90+
91+
// End AvaticaClosedResultSetWithNullStatementTest.java

0 commit comments

Comments
 (0)