Skip to content

Commit 918133c

Browse files
author
jielongping
committed
[jdbc-v2] Fix NPE in ResultSetMetaDataImpl#getColumnClassName
1 parent 2d305b7 commit 918133c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/ResultSetMetaDataImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ public boolean isDefinitelyWritable(int column) throws SQLException {
179179
@Override
180180
public String getColumnClassName(int column) throws SQLException {
181181
try {
182-
return typeClassMap.getOrDefault(getColumn(column).getDataType(), Object.class).getName();
182+
Class<?> columnClassType = typeClassMap.get(getColumn(column).getDataType());
183+
if (columnClassType == null) {
184+
columnClassType = Object.class;
185+
}
186+
return columnClassType.getName();
183187
} catch (Exception e) {
184188
throw ExceptionUtils.toSqlState(e);
185189
}

jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/ResultSetMetaDataImplTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ public void testGetColumnTypeIntegers() throws Exception {
7777
}
7878
}
7979

80+
@Test
81+
public void testGetColumnTypeMap() throws Exception {
82+
try (Connection conn = getJdbcConnection()) {
83+
try (Statement stmt = conn.createStatement()) {
84+
ResultSet rs = stmt.executeQuery("select map('a', 1) as a");
85+
ResultSetMetaData rsmd = rs.getMetaData();
86+
assertEquals(rsmd.getColumnType(1), Types.JAVA_OBJECT);
87+
assertEquals(rsmd.getColumnClassName(1), Object.class.getName());
88+
}
89+
}
90+
}
91+
8092
@Test(groups = { "integration" })
8193
public void testGetColumnTypeFloats() throws Exception {
8294
try (Connection conn = getJdbcConnection()) {

0 commit comments

Comments
 (0)