@@ -1067,6 +1067,65 @@ public void testNestedArrays() throws Exception {
10671067 }
10681068 }
10691069
1070+ /**
1071+ * Test for https://github.com/ClickHouse/clickhouse-java/issues/2723
1072+ * getString() on nested arrays was failing with NullPointerException due to re-entrancy bug
1073+ * in DataTypeConverter when converting nested arrays to string representation.
1074+ */
1075+ @ Test (groups = { "integration" })
1076+ public void testNestedArrayToString () throws SQLException {
1077+ // Test 1: Simple nested array - getString on Array(Array(Int32))
1078+ try (Connection conn = getJdbcConnection ()) {
1079+ try (Statement stmt = conn .createStatement ()) {
1080+ try (ResultSet rs = stmt .executeQuery ("SELECT [[1, 2, 3], [4, 5, 6]] as nested_array" )) {
1081+ assertTrue (rs .next ());
1082+ // This was throwing NullPointerException before the fix
1083+ String result = rs .getString ("nested_array" );
1084+ assertEquals (result , "[[1, 2, 3], [4, 5, 6]]" );
1085+ }
1086+ }
1087+ }
1088+
1089+ // Test 2: Query similar to issue #2723 with splitByChar returning array
1090+ // The original issue was that getString() on an array column inside a CASE/WHEN
1091+ // would cause NPE. This test verifies that getString() works correctly on arrays.
1092+ try (Connection conn = getJdbcConnection ()) {
1093+ try (Statement stmt = conn .createStatement ()) {
1094+ String query = "SELECT " +
1095+ "splitByChar('_', 'field1_field2_field3') as split_result, " +
1096+ "CASE " +
1097+ " WHEN " +
1098+ " splitByChar('_', 'field1_field2_field3')[1] IN ('field1', 'field2') " +
1099+ " AND match( " +
1100+ " splitByChar('_', 'field1_field2_field3')[2], " +
1101+ " '(field1|field2|field3)' " +
1102+ " ) " +
1103+ " THEN 'Matched' " +
1104+ " ELSE 'NotMatched' " +
1105+ "END AS action_to_do" ;
1106+ try (ResultSet rs = stmt .executeQuery (query )) {
1107+ assertTrue (rs .next ());
1108+ // The key test is that getString() doesn't throw NPE on array column
1109+ String splitResult = rs .getString ("split_result" );
1110+ assertEquals (splitResult , "['field1', 'field2', 'field3']" );
1111+ String actionResult = rs .getString ("action_to_do" );
1112+ assertEquals (actionResult , "Matched" );
1113+ }
1114+ }
1115+ }
1116+
1117+ // Test 3: Deeply nested arrays - Array(Array(Array(String)))
1118+ try (Connection conn = getJdbcConnection ()) {
1119+ try (Statement stmt = conn .createStatement ()) {
1120+ try (ResultSet rs = stmt .executeQuery ("SELECT [[['a', 'b'], ['c']], [['d', 'e', 'f']]] as deep_nested" )) {
1121+ assertTrue (rs .next ());
1122+ String result = rs .getString ("deep_nested" );
1123+ assertEquals (result , "[[['a', 'b'], ['c']], [['d', 'e', 'f']]]" );
1124+ }
1125+ }
1126+ }
1127+ }
1128+
10701129 @ Test (groups = { "integration" })
10711130 public void testMapTypes () throws SQLException {
10721131 runQuery ("CREATE TABLE test_maps (order Int8, "
0 commit comments