From 930ab852fbaefb45506f311b402a1e39a17574fa Mon Sep 17 00:00:00 2001 From: roha4naik Date: Tue, 17 Nov 2026 14:46:38 +0530 Subject: [PATCH] fix(client-v2): keep server time zone as TimeZone in loadServerInfo Client.loadServerInfo() stored the server time zone as a String, but Client.getServerTimeZone() casts the configuration value to TimeZone. Every getServerTimeZone() call after loadServerInfo() failed with ClassCastException. Store the value through ClientConfigProperties.SERVER_TIMEZONE.parseValue(), the same conversion that the client uses when it parses its configuration. Closes #3357 --- .../java/com/clickhouse/client/api/Client.java | 3 ++- .../java/com/clickhouse/client/ClientTests.java | 16 ++++++++++++++++ history/latest/3357.md | 4 ++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 history/latest/3357.md diff --git a/client-v2/src/main/java/com/clickhouse/client/api/Client.java b/client-v2/src/main/java/com/clickhouse/client/api/Client.java index 0d843d3c0..348567da1 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/Client.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/Client.java @@ -258,7 +258,8 @@ public void loadServerInfo() { if (tmpDbUser != null && !tmpDbUser.isEmpty()) { this.dbUser = tmpDbUser; } - this.configuration.put(ClientConfigProperties.SERVER_TIMEZONE.getKey(), reader.getString("timezone")); + this.configuration.put(ClientConfigProperties.SERVER_TIMEZONE.getKey(), + ClientConfigProperties.SERVER_TIMEZONE.parseValue(reader.getString("timezone"))); serverVersion = reader.getString("version"); } } diff --git a/client-v2/src/test/java/com/clickhouse/client/ClientTests.java b/client-v2/src/test/java/com/clickhouse/client/ClientTests.java index 050e6cd0c..5f41dba90 100644 --- a/client-v2/src/test/java/com/clickhouse/client/ClientTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/ClientTests.java @@ -322,6 +322,22 @@ public void testLoadingServerContext() throws Exception { } } + @Test(groups = {"integration"}) + public void testServerTimeZoneAfterLoadingServerInfo() throws Exception { + try (Client client = newClient().build()) { + // Before loadServerInfo() the client returns the configured value. + Assert.assertEquals(client.getServerTimeZone(), "UTC"); + + String expected = client.queryAll("SELECT timezone()").get(0).getString(1); + client.loadServerInfo(); + Assert.assertEquals(client.getServerTimeZone(), expected); + } + + try (Client client = newClient().setServerTimeZone("Europe/Berlin").build()) { + Assert.assertEquals(client.getServerTimeZone(), "Europe/Berlin"); + } + } + @Test(groups = {"integration"}) public void testDisableNative() { try (Client client = newClient().disableNativeCompression(true).build()) { diff --git a/history/latest/3357.md b/history/latest/3357.md new file mode 100644 index 000000000..7e1e1c53c --- /dev/null +++ b/history/latest/3357.md @@ -0,0 +1,4 @@ +- **[client-v2]** Fixed `Client#getServerTimeZone()`, which failed with `ClassCastException` (`String` cannot be cast + to `TimeZone`) after a call to `Client#loadServerInfo()`. `loadServerInfo()` now stores the server time zone as a + `TimeZone`, the same type as the parsed client configuration. + (https://github.com/ClickHouse/clickhouse-java/issues/3357)