[client-v2] Reading Array(IPv6) / Array(Nullable(IPv6)) fails when an element is an IPv4-mapped address (::ffff:a.b.c.d)
Maintainer antworten meist innerhalb von 1 Tag
@hutiefang76 arbeitet bereits daran.
Seit 19.10.2026.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 72/100
Rechercherichtung
Start with BinaryStreamReader.java, especially readArrayItem and resolveArrayItemClass, which the issue identifies as the two paths that choose IPv6 array component types. Reproduce with the mixed IPv6 and IPv4-mapped IPv6 queries in the issue, then run the relevant client-v2 reader and jdbc-v2 tests. Done when nullable and non-nullable arrays read mixed addresses without losing rows, while Array(IPv4) remains Inet4Address[].
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description
The binary reader cannot read an Array(IPv6) or Array(Nullable(IPv6)) value that contains an IPv4-mapped address (::ffff:a.b.c.d), unless every element of the array is IPv4-mapped. The read throws IllegalArgumentException: array element type mismatch. The failure is at record level, so the complete row is lost: in jdbc-v2, ResultSet.next() throws.
Affected shapes (verified on a live server, RowBinaryWithNamesAndTypes and Native):
| Value | Result |
|---|---|
[toNullable(toIPv6('2001:db8::1')), NULL] |
OK |
[toNullable(toIPv6('::ffff:10.0.0.1'))] |
fails |
[NULL, toNullable(toIPv6('::ffff:10.0.0.1'))] |
fails |
[toIPv6('::ffff:10.0.0.1')] (all elements mapped) |
OK |
[toIPv6('2001:db8::1'), toIPv6('::ffff:10.0.0.1')] |
fails |
[toIPv6('::ffff:10.0.0.1'), toIPv6('2001:db8::1')] |
fails |
[[toIPv6('2001:db8::1'), toIPv6('::ffff:10.0.0.1')]] |
fails |
Array(Nullable(IPv6)) table column with value ['2001:db8::1', NULL, '::ffff:10.0.0.1'] |
fails |
map(..., IPv6) / tuple(IPv6, IPv6) with mixed values |
OK |
The same failures occur through Client.newBinaryFormatReader(...), Client.queryAll(...) and jdbc-v2 Statement.executeQuery(...).
Steps to reproduce
- Run
SELECT [toNullable(toIPv6('::ffff:10.0.0.1'))] AS aorSELECT [toIPv6('2001:db8::1'), toIPv6('::ffff:10.0.0.1')] AS awith client-v2 or jdbc-v2. - Read the row.
- The read throws the exception below.
The server returns these values without problems:
$ curl ... --data-binary "SELECT [toNullable(toIPv6('::ffff:10.0.0.1'))] AS a, toTypeName(a)"
['::ffff:10.0.0.1'] Array(Nullable(IPv6))
$ curl ... --data-binary "SELECT [toIPv6('2001:db8::1'), toIPv6('::ffff:10.0.0.1')] AS a, toTypeName(a)"
['2001:db8::1','::ffff:10.0.0.1'] Array(IPv6)
Error Log or Exception StackTrace
com.clickhouse.client.api.ClientException: Failed to read value for column a
Caused by: java.lang.IllegalArgumentException: Failed to set value at index: 0 value /10.0.0.1 of class java.net.Inet4Address when array type is class [Ljava.net.Inet6Address;
Caused by: java.lang.IllegalArgumentException: array element type mismatch
Reverse order ([toIPv6('::ffff:10.0.0.1'), toIPv6('2001:db8::1')]):
java.lang.IllegalArgumentException: Failed to set value at index: 1 value /2001:db8:0:0:0:0:0:1 of class java.net.Inet6Address when array type is class [Ljava.net.Inet4Address;
jdbc-v2: the same chain, wrapped in java.sql.SQLException: Failed to read value for column a, thrown from ResultSet.next().
Expected Behaviour
The read succeeds and the array holds one InetAddress for each element, as the server returns. A scalar IPv6 value that is IPv4-mapped already reads correctly as Inet4Address (see #2140). An array of the same values must also read correctly.
Root cause
BinaryStreamReader.java:254reads IPv6 withInet6Address.getByAddress(readNBytes(input, 16)). This is the staticInetAddress.getByAddress(byte[]). For an IPv4-mapped address it returns anInet4Address, otherwise anInet6Address.- Nullable element:
readArrayItem(lines 803-808) creates the backing array withresolveArrayItemClass(...). For IPv6 this falls to the default branch (line 877),dataType.getObjectClass(), which isInet6Address.class(ClickHouseDataType.java:101).Array.set(...)of anInet4Addresselement into anInet6Address[]throws. - Non-nullable element:
readArrayItem(lines 817-818) uses the class of the first element as the component type. When a later element has the otherInetAddresssubclass,Array.set(...)throws. Thus an array works only if all its elements are mapped, or none are.
Suggested fix
Use InetAddress.class as the array component type for IPv6 elements, in both branches:
resolveArrayItemClass: returnInetAddress.classforIPv6(nullable branch; the non-nullable branch too, so that empty arrays get the same type).readArrayItem, non-nullable branch: useInetAddress.classforIPv6instead offirstValue.getClass().
I tested this change locally: all failing shapes in the table above then read correctly, through the client-v2 reader, queryAll, and jdbc-v2, in RowBinaryWithNamesAndTypes and Native.
Contrast cases:
Array(IPv4)must stayInet4Address[]. IPv4 always decodes toInet4Address.- The fix changes the runtime component type for IPv6 arrays to
InetAddress[]. Today the type already depends on the data (Inet4Address[]for an all-mapped array,Inet6Address[]otherwise). The change agrees with the jdbc-v2 type mapping in #3191, which reportsjava.net.InetAddressfor IPv6.
Code Example
Client client = new Client.Builder()
.addEndpoint("http://localhost:8123")
.setUsername("default").setPassword("")
.build();
// Array(Nullable(IPv6)) with an IPv4-mapped element: throws
client.queryAll("SELECT [toNullable(toIPv6('::ffff:10.0.0.1'))] AS a");
// Array(IPv6) with a plain and an IPv4-mapped element (either order): throws
client.queryAll("SELECT [toIPv6('2001:db8::1'), toIPv6('::ffff:10.0.0.1')] AS a");
// jdbc-v2
try (Connection conn = DriverManager.getConnection("jdbc:clickhouse://localhost:8123/default", "default", "");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT [toNullable(toIPv6('::ffff:10.0.0.1'))] AS a")) {
rs.next(); // throws SQLException: Failed to read value for column a
}
Configuration
Client Configuration
// defaults; only endpoint and credentials set
Environment
- Cloud
- Client version:
main@ 67a6b9e (0.12.0-rc1-SNAPSHOT) - Language version: OpenJDK 17.0.20
- OS: Linux (Docker)
ClickHouse Server
- ClickHouse Server version: 26.9.1.1629
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved:CREATE TABLE ipv6_arr (id Int32, a Array(Nullable(IPv6)), f Float64) ENGINE = MergeTree ORDER BY id; INSERT INTO ipv6_arr VALUES (1, ['2001:db8::1', NULL, '::ffff:10.0.0.1'], 1.5); SELECT a FROM ipv6_arr ORDER BY id; -- fails- Sample data for all these tables: above
Found by automated analysis of the client (Polyglot AI) while working on #3189. Verified against a live ClickHouse server with a reproduction program, not only by code inspection.
- Vorherrschende Sprache
- Java
- Sterne
- 1.6k
- Forks
- 649
- Ø Merge
- 1 T. 20 Std.
- Gemergte PRs (30 T.)
- 39
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus ClickHouse/clickhouse-java
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
ClickHouse/clickhouse-java#3349 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug jdbc-v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
ClickHouse/clickhouse-java#3347 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug jdbc-v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
ClickHouse/clickhouse-java#3326 ·
Maintainer antworten meist innerhalb von 1 Tag
-
[client-v2] Enum8/Enum16 insert accepts a non-member integer and uses Enum.ordinal(), silently storing values that are not enum membersEvtl. vergeben @jaya232 hat das vor 6 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
ClickHouse/clickhouse-java#3304 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug jdbc-v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
ClickHouse/clickhouse-java#3214 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in ClickHouse/clickhouse-java
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
bug:unconfirmed
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
UniversalMediaServer/UniversalMediaServer#6473 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
StarRocks/starrocks#83246 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 2 Tagen