Describe the bug
Reading a UInt64 column into a primitive POJO field (e.g. private long) always fails with a
ClassCastException. Only boxed fields (BigInteger, Long) work, because those take the generic
BinaryStreamReader.readValue(...) path.
Steps to reproduce
@Data @AllArgsConstructor @NoArgsConstructor
public static class Dto {
private int rowId;
private long u64; // primitive
private long trailing;
}
final String sql = "SELECT toInt32(1) AS rowId, toUInt64(5) AS u64, toInt64(777) AS trailing";
TableSchema schema = client.getTableSchemaFromQuery(sql);
client.register(Dto.class, schema);
client.queryAll(sql, Dto.class, schema);
Expected behaviour
The UInt64 value is set on the primitive field.
Error log
ClientException: Failed to get query response
-> ClientException: Failed to set value of 'u64
-> java.lang.ClassCastException: class com.clickhouse.client.api.data_formats.internal.BinaryStreamReader
cannot be cast to class java.math.BigInteger
Root cause
SerializerUtils.compilePOJOSetter has a dedicated branch for a primitive target field bound to a
UInt64 column (client-v2, around line 1239 on main):
} else if (targetType.isPrimitive() && column.getDataType() == ClickHouseDataType.UInt64) {
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(BigInteger.class));
mv.visitMethodInsn(INVOKEVIRTUAL, BigInteger, targetType.getSimpleName() + "Value", ...);
At that point the operand stack holds [dtoObject, reader] — the branch never emits any
readValue/read* call, so the CHECKCAST is applied to the BinaryStreamReader instance itself
and the generated setter can never succeed. Nothing is read from the stream either, so the branch is
unusable for every primitive type, not just long.
Configuration
- Client version:
main
- Client module:
client-v2 (POJO read path)
- Server version: any (reproduced on
latest)
Describe the bug
Reading a
UInt64column into a primitive POJO field (e.g.private long) always fails with aClassCastException. Only boxed fields (BigInteger,Long) work, because those take the genericBinaryStreamReader.readValue(...)path.Steps to reproduce
Expected behaviour
The
UInt64value is set on the primitive field.Error log
Root cause
SerializerUtils.compilePOJOSetterhas a dedicated branch for a primitive target field bound to aUInt64column (client-v2, around line 1239 onmain):At that point the operand stack holds
[dtoObject, reader]— the branch never emits anyreadValue/read*call, so theCHECKCASTis applied to theBinaryStreamReaderinstance itselfand the generated setter can never succeed. Nothing is read from the stream either, so the branch is
unusable for every primitive type, not just
long.Configuration
mainclient-v2(POJO read path)latest)