[client-v2] getShortArray/getIntArray/getLongArray throw ClassCastException on an empty Array(UInt8/UInt16/UInt32)
Maintainer thường phản hồi trong vòng 1 ngày
@abdalrahmanehab đang làm issue này rồi.
Từ ngày 21/11/2026.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 80/100
Hướng nghiên cứu
Bắt đầu với BinaryStreamReader.readArray() và cách xử lý mảng rỗng trong BinaryStreamReaderTests, đặc biệt là provider emptyArrayComponentTypes. So sánh cách chọn kiểu thành phần cho mảng không dấu rỗng và không rỗng, sau đó xác minh các accessor có kiểu tương ứng trả về mảng có độ dài bằng không cho UInt8, UInt16 và UInt32. Issue đề xuất kiểm thử hồi quy thông qua queryAll() và newBinaryFormatReader(), với một cột độ rộng cố định sau mỗi mảng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
On main and 0.11.2, getShortArray(), getIntArray() and getLongArray() fail with ClassCastException on an empty Array(UInt8), Array(UInt16) or Array(UInt32). On a non-empty array of the same column, the same call returns the correct value. So the same call works on some rows and fails on other rows.
An empty array and a non-empty array of one column get different Java component types:
| Column type | non-empty value | empty value | accessor for non-empty | accessor on empty |
|---|---|---|---|---|
Array(UInt8) |
short[] |
byte[] |
getShortArray() OK |
getShortArray() fails |
Array(UInt16) |
int[] |
short[] |
getIntArray() OK |
getIntArray() fails |
Array(UInt32) |
long[] |
int[] |
getLongArray() OK |
getLongArray() fails |
Array(Int8/Int16/Int32/Int64), Array(Float32/Float64), Array(Bool) |
same type for both | OK | OK |
This occurs on all read paths: queryAll() (MapBackedRecord, a bare ClassCastException), and newBinaryFormatReader() and queryRecords() (ClientException: Value cannot be converted to an array of primitives, caused by the ClassCastException). getObjectArray() and getList() work for both rows. The column after the array is read correctly, so the stream is not desynchronized.
This is a regression in 0.11.2. On 0.11.1, the empty and the non-empty array have the same component type for all three types, and each accessor that works on [1] also works on [].
Steps to reproduce
- Run the code example below against any server.
getShortArray("a")on[1, 2]returns[1, 2].getShortArray("b")on[]of the same type throwsClassCastException.
Error Log or Exception StackTrace
non-empty: [1, 2]
Exception in thread "main" java.lang.ClassCastException: class [B cannot be cast to class [S ([B and [S are in module java.base of loader 'bootstrap')
at com.clickhouse.client.api.data_formats.internal.MapBackedRecord.getShortArray(MapBackedRecord.java:315)
at Min.main(Min.java:12)
With newBinaryFormatReader():
com.clickhouse.client.api.ClientException: Value cannot be converted to an array of primitives
Caused by: java.lang.ClassCastException: class [B cannot be cast to class [S
Expected Behaviour
An accessor that works on a non-empty value of a column also works on an empty value of that column, and returns a zero-length array: short[0], int[0] or long[0]. That is the 0.11.1 behavior. The server sends the same column type for both values:
$ curl ... --data-binary "SELECT toTypeName(CAST([] AS Array(UInt8))) e, toTypeName(CAST([1] AS Array(UInt8))) n, CAST([] AS Array(UInt8)) ev, CAST([1] AS Array(UInt8)) nv FORMAT TSVWithNames"
e n ev nv
Array(UInt8) Array(UInt8) [] [1]
Code Example
Reproduction program (Java, 15 lines)
import com.clickhouse.client.api.Client;
import com.clickhouse.client.api.query.GenericRecord;
import java.util.Arrays;
public class Min {
public static void main(String[] args) {
try (Client client = new Client.Builder().addEndpoint("http://localhost:8123")
.setUsername("default").setPassword("").build()) {
GenericRecord r = client.queryAll(
"SELECT CAST([1, 2] AS Array(UInt8)) AS a, CAST([] AS Array(UInt8)) AS b").get(0);
System.out.println("non-empty: " + Arrays.toString(r.getShortArray("a")));
System.out.println("empty: " + Arrays.toString(r.getShortArray("b")));
}
}
}
Root cause
readValue()readsUInt8asShort,UInt16asIntegerandUInt32asLong(BinaryStreamReader.java:174-183).readArrayToArrayValue()takes the component type of a non-empty array from the first value, so it makesshort[],int[],long[](BinaryStreamReader.java:809-834).- An empty array takes its component type from
getPrimitiveClass(), which is not widened:byte,short,int(BinaryStreamReader.java:784-786). In 0.10.0 to 0.11.1 this branch usedgetWiderPrimitiveClass()(#2920); #3343 reverted it. getPrimitiveArray()returns the backing array without conversion, and the caller casts it to the requested array type (MapBackedRecord.java:263-273, AbstractBinaryFormatReader.java:523-555).
A review comment on #3343 found this (comment), and the reply was "yes, this need to be addressed, will fix". main does not have a fix.
The fix is one call in the empty-array branch of readArray(); it changes only UInt8, UInt16 and UInt32.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related
- #3395: near cause, but non-empty
Array(Nullable(String))andgetStringArray().
Configuration
Client Configuration
new Client.Builder().addEndpoint("http://localhost:8123").setUsername("default").setPassword("").build()
Environment
- Cloud
- Client version:
mainat 75063012b (0.12.0-rc1-SNAPSHOT), same code in 0.11.2. Not affected: 0.11.1. - Language version: OpenJDK 17.0.21
- OS: Linux (Ubuntu container)
ClickHouse Server
- ClickHouse Server version: 26.10.4.207
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: none (literalCASTexpressions)- Sample data for all these tables: none
Classification: impact: none · area: Data types & formats (Array(UInt8), Array(UInt16), Array(UInt32))
Found by automated analysis (Polyglot AI) while working on #3395. Verified against a live server. Shortened on 2026-11-20: the edit history has the first version.
- Ngôn ngữ chính
- Java
- Star
- 1.6k
- Fork
- 657
- Merge trung bình
- 2 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 36
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ClickHouse/clickhouse-java
-
api-diagnostics bug jdbc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
ClickHouse/clickhouse-java#3464 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ClickHouse/clickhouse-java#3452 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug jdbc performance queries sql-parser
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
ClickHouse/clickhouse-java#3451 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug jdbc legacy queries
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
ClickHouse/clickhouse-java#3444 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
api-diagnostics bug client jdbc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ClickHouse/clickhouse-java#3439 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của ClickHouse/clickhouse-java
Issue tương tự
-
[BUG] Nightly Build JDK 17: latest-frameworks job red since 2026-11-28 — quarkiverse-langchain4j 2.0.0 pins Quarkus 4.0.0, which requires Java 21Có thể đã có người làm @uhhgxg đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
langchain4j/langchain4j#7344 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
cristianEncarnacion/ferroreport#149 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
quelea-projection/Quelea#749 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
erkamyaman/rust-anything#963 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 76/100