Repository navigation
fix(client-v2): reject unknown time zone IDs instead of falling back to GMT - #3359
Conversation
…to GMT QuerySettings#setUseTimeZone and the TimeZone-typed client options (use_time_zone, server_time_zone) converted the ID with TimeZone.getTimeZone(String), which returns GMT for an ID it does not recognise. A typo in a time zone ID was accepted and date-time values were then interpreted in GMT. Add ValidationUtils#toTimeZone, which validates the ID with ZoneId.of and throws SettingsValidationException for an unknown or malformed ID. It converts UTC+/UT+ prefixed offset IDs through their offset (TimeZone returns GMT for them too) and rejects offsets with seconds, which TimeZone cannot represent. QuerySettings#setUseTimeZone and ClientConfigProperties#parseValue use it, so Client.Builder and jdbc-v2 connection properties are covered too. Fixes: #3286 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Auto-approved by the AI review gate on 62c20a9. Details in the approver's comment on this pull request.
AI review gate — auto-approved
History (latest 5 heads, newest first)
|
Client V2 CoverageCoverage Report
Class Coverage
|
JDBC V2 CoverageCoverage Report
Class Coverage
|
…ersion ValidationUtils#toTimeZone rejected a fixed offset with seconds (+05:30:45) only when TimeZone#getTimeZone(ZoneId) returned a different offset. That is true on Java 8, 11 and 17, which return GMT, but on Java 21 TimeZone represents the offset exactly. So the same ID was rejected on one runtime and accepted on another, and the SettingsTests rows for seconds offsets failed in the JDK 21 CI job. Reject a fixed offset whose total seconds are not a whole number of minutes, independent of the runtime. Region zones are not affected: the check applies to fixed offsets only (Africa/Monrovia, -00:44:30 at the epoch, stays valid). Fixes: #3286 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TriageCategory: Summary What this impacts
Concerns
Required reviewer action
|
There was a problem hiding this comment.
Auto-approved by the AI review gate on 47c1137. Details in the approver's comment on this pull request.
…ezone-ids # Conflicts: # docs/features.md
There was a problem hiding this comment.
Auto-approved by the AI review gate on 5a069ad. Details in the approver's comment on this pull request.
|
@polyglotAI-bot resolve conflicts please with main |
…ezone-ids # Conflicts: # client-v2/src/main/java/com/clickhouse/client/api/ClientConfigProperties.java # client-v2/src/test/java/com/clickhouse/client/api/ClientConfigPropertiesTest.java # docs/features.md
d9613a0
|
Resolved the conflicts with |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d9613a0. Configure here.
AI review gate — Human approval in place of AI reviewApproved on the head commit by chernser (write access, not the author), standing in for the AI review:
What to do:
Evaluated at |

Summary
Fixes #3286.
Root cause.
QuerySettings#setUseTimeZone(String)andClientConfigProperties#parseValue(the parser for theTimeZone-typed optionsuse_time_zoneandserver_time_zone) converted the ID withTimeZone.getTimeZone(String). That method returnsGMTfor an ID that it does not recognise. So a typo such asAmerica/Los_Angelswas accepted, and date-time values were then interpreted inGMT.Client.Builder#buildalready validatesuse_time_zonewithZoneId.of, butQuerySettings#setUseTimeZoneandserver_time_zone(whenuse_time_zoneis also set) had no check.A second form of the same defect:
ZoneId.ofaccepts the offset IDsUTC+05:30andUT-03:00, butTimeZonedoes not know them.TimeZone.getTimeZone("UTC+05:30")and alsoTimeZone.getTimeZone(ZoneId.of("UTC+05:30"))returnGMT(verified on JDK 8 and 17). SoClient.Builder#useTimeZone("UTC+05:30")passed thebuild()check and was then silently read asGMT. The plain offset+05:30had the same result throughTimeZone.getTimeZone(String).Fix. A new helper
ValidationUtils#toTimeZone(String, String)validates the ID withZoneId.ofand throwsSettingsValidationException(anIllegalArgumentException, the type thatQuerySettingsandClient.Builder#buildalready throw for these settings) with the setting name and the rejected ID. It convertsUTC±/UT±offset IDs through their offset, so thatTimeZonegets the correct offset. It rejects a fixed offset with seconds (+05:30:45):ZoneIdaccepts it, but on Java 17 and earlierTimeZone#getTimeZonereturnsGMTfor it. The check uses the offset itself, not theTimeZoneresult, so the same ID is rejected on every Java version (on Java 21,TimeZonerepresents the offset exactly).QuerySettings#setUseTimeZoneandClientConfigProperties#parseValueuse the helper. jdbc-v2 gets the fix throughClientConfigProperties: it sendsuse_time_zone/server_time_zoneconnection properties toClient.Builder, and it has no time zone ID parsing of its own.Review of time zone ID usage in client-v2 and jdbc-v2
As requested on the issue, I checked every place in
client-v2andjdbc-v2that makes aTimeZone/ZoneIdfrom a string:QuerySettings#setUseTimeZoneClientConfigProperties#parseValue(use_time_zone,server_time_zone; used byClient.Builder,Client.Builder#setOption, jdbc-v2 properties)Client.Builder#buildvalidationZoneId.ofand throws.QueryResponseconstructor,X-ClickHouse-TimezoneheaderBinaryStreamReader#resolveTimeZone,clickhouse-dataClickHouseColumn(DateTime('<tz>')type parameters)TableSchema)ZoneId.of("UTC")constants,Calendar#getTimeZone()in jdbc-v2The two server-supplied places are not changed in this PR:
QueryResponseparses the header for every response, also when the client usesuse_time_zone. If it threw for a server time zone that the JDK tzdata does not know, every query would fail, and settinguse_time_zonecould not work around it. This needs its own decision (fail only when the server time zone is actually used?). I can do it in a follow-up if you want.ClickHouseColumnis inclickhouse-dataand is shared with the v1 client.BinaryStreamReader#resolveTimeZonedepends on its current fallback for the server's syntheticFixed/UTC±HH:MM:SSnames (Fix ClickHouseColumn: resolve Fixed/UTC±HH:MM:SS timezone names to correct offset #2877). A throw there would make such columns unreadable. Known gap: a schema that user code builds, for exampleClickHouseColumn.of("c", "DateTime('Europe/Berln')")forClient#register, also getsGMTsilently. A fix needs a parse that is strict for user input and keeps theFixed/UTChandling for server metadata, so I suggest a separate issue.Changes
client-v2ValidationUtils: addtoTimeZone(String timeZoneId, String name).client-v2QuerySettings#setUseTimeZone: usetoTimeZone.client-v2ClientConfigProperties#parseValue: usetoTimeZoneforTimeZone-typed options.history/latest/3286.md: changelog entry.docs/features.md: document the accepted ID format.Compatibility
IllegalArgumentExceptionfromQuerySettings#setUseTimeZone, fromClient.Builder#build(forserver_time_zonetoo), and from a jdbc-v2 connect (asSQLException, causeIllegalArgumentException). Before, it was replaced withGMT.java.util.TimeZoneIDs thatZoneId.ofdoes not accept are now rejected byQuerySettings#setUseTimeZone, and forserver_time_zoneset together withuse_time_zone: three-letter aliases (PST,IST,EST) and custom forms (GMT+5:30,GMT+530,GMT+20).Client.Builder#buildalready rejected all of them foruse_time_zone(and forserver_time_zonewhenuse_server_time_zoneis on). The changelog entry is under "Breaking changes" and names the replacements.+05:30:45,GMT+05:30:45) are rejected on every Java version:ZoneIdaccepts them, but on Java 17 and earlierTimeZonereturnsGMTfor them. On Java 21,GMT+05:30:45was accepted before this change.UTC±hh:mm,UT±hh:mmand±hh:mmnow give their offset (TimeZone IDGMT±hh:mm) instead ofGMT.TimeZone(ID and rules) is the same as before: region IDs,UTC,GMT,Etc/*,GMT±hh:mm. The tests pin these forms.ValidationUtilsis in theinternalpackage.Test
SettingsTests#testQuerySettingsUseTimeZone(unit,@DataProvider): valid IDs give the expectedTimeZoneID and offset. The rows forAmerica/Los_Angeles,UTC,GMT,Etc/GMT+5,GMT+05:30pin unchanged results. The rows for+05:30,UTC+05:30,UT-03:00failed onmain(GMT).SettingsTests#testQuerySettingsUseTimeZoneRejectsInvalidId(unit,@DataProvider): unknown region, typo, empty, leading space, out-of-range offset, malformed offset, offsets with seconds are rejected, the message names the setting and the ID, and the setting is not stored. All rows failed onmain(nothing thrown).ClientConfigPropertiesTest#testTimeZoneParsing(unit, bothuse_time_zoneandserver_time_zone): valid region ID unchanged,UTC+05:30gets its offset, unknown ID is rejected.QueryTests#testUseTimeZone(integration, live read path,@DataProvider):SELECT toDateTime(0)read with the time zone set on the client (Client.Builder#useTimeZone) and set per query (QuerySettings#setUseTimeZone) returns epoch 0 at the local time of that zone. Onmain,UTC+05:30and+05:30gave00:00instead of05:30on both paths. TheEurope/Berlinrow is the contrast case.ConnectionTest#testInvalidTimeZoneIdRejected(jdbc-v2 integration): an invaliduse_time_zoneorserver_time_zoneconnection property fails the connect. Theserver_time_zonerow failed onmain(the connection was opened withGMT). Theuse_time_zonerow already passed onmain(build()checks it) and guards that path.Runs (ClickHouse 26.10.4.207, JDK 17; helper also checked on JDK 8):
client-v2unit tests: 854 passed.client-v2integrationQueryTests,ClientTests,DataTypeTests,ParameterizedQueryTest: 316/318 passed. The 2 failures areClientTests#testAddSecureEndpoint, which also fails onmainin my local environment (TLS endpoint not available locally).jdbc-v2unit tests: 2029 passed. IntegrationConnectionTest,JDBCDateTimeTests(fresh database): 76/79 passed. The 3 failures are the SSL tests, which also fail onmainin my local environment (no TLS endpoint). An earlier run that also includedJdbcDataTypeTestsandDetachedResultSetTesthad no failure related to this change.packages/clickhouse-jdbc-all(-am package): builds.Checklist
history/latest/3286.md)docs/changes_checklist.md: "Exception handling changed" (type staysIllegalArgumentException, matches siblings; no failure is swallowed), "Existing configuration property changed" (no key or default change; parsing now rejects invalid values; checked the end-to-end JDBC property path), "New method added" (internal helper, smallest visibility that both callers in different packages can use)docs/features.mdupdated (time zone setting contract)Closes #3286
🤖 Generated with Claude Code
Note
Medium Risk
Breaking configuration behavior for invalid or legacy time zone strings affects how DateTime values are decoded; parsing is stricter but limited to client/JDBC time zone settings, not server metadata paths left unchanged.
Overview
Replaces silent
GMTfallback when parsing user-supplied time zone IDs with strict validation via newValidationUtils.toTimeZone:ZoneId.ofmust accept the ID,UTC±/UT±offsets are normalized soTimeZonegets the right offset, and fixed offsets with seconds are rejected for consistent behavior across Java versions.QuerySettings#setUseTimeZone,ClientConfigPropertiesparsing foruse_time_zone/server_time_zone, and JDBC properties that flow through the same path now throwIllegalArgumentExceptionon unknown, typo, or unsupported IDs instead of misinterpreting datetimes inGMT. Legacy three-letter aliases and some non-ZoneIdforms that were already rejected at client build time are now rejected consistently everywhere.Docs and changelog document the breaking contract; unit and integration tests cover valid IDs, rejection cases, live
DateTimereads, and JDBC connect failures.Reviewed by Cursor Bugbot for commit d9613a0. Bugbot is set up for automated code reviews on this repo. Configure here.