From d80658178f7f455b770a210765cc9668d88b3b68 Mon Sep 17 00:00:00 2001 From: Sergey Chernov Date: Mon, 23 Feb 2026 17:08:26 -0800 Subject: [PATCH 1/2] removed default port adjustment --- CHANGELOG.md | 7 +++ .../jdbc/internal/JdbcConfiguration.java | 13 ++---- .../jdbc/internal/JdbcConfigurationTest.java | 44 +++++++++---------- 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 085cf89b9..10ee917f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.9.7 + +### Breaking changes +- [jdbc] Default port is not added anymore - now port should be explicitly set. Previously `http://localhost` was transformed to `http://localhost:8123`. +Parsing URL with standard tools is not stable because `URI.create()` doesn't guarantee correct port number parsing. +Implementing more complex logic for minor case would add even more complexity. (https://github.com/ClickHouse/clickhouse-java/issues/2753) + ## 0.9.6 Release is aimed to address potential security risk in one of the dependencies (see below). We strongly recommend to upgrade. diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java index 21d05a552..c20801b3a 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java @@ -8,6 +8,7 @@ import com.clickhouse.jdbc.DriverProperties; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import org.apache.hc.client5.http.utils.URIUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -148,20 +149,14 @@ public String getConnectionUrl() { * @param ssl - if SSL protocol should be used * @return URL without JDBC prefix */ - private static String createConnectionURL(String url, boolean ssl) throws SQLException { + static String createConnectionURL(String url, boolean ssl) throws SQLException { String adjustedURL = ssl && url.startsWith("http://") ? "https://" + url.substring(7) : url; try { URI tmp = URI.create(adjustedURL); - String asciiString = tmp.toASCIIString(); - if (tmp.getPort() < 0) { - String port = ssl || adjustedURL.startsWith("https") - ? ":" + ClickHouseHttpProto.DEFAULT_HTTPS_PORT - : ":" + ClickHouseHttpProto.DEFAULT_HTTP_PORT; - asciiString += port; - } - return asciiString; + // URI may incorrectly parse port and logic based on port number is unstable. + return tmp.toASCIIString(); } catch (IllegalArgumentException iae) { throw new SQLException("Failed to parse URL '" + url + "'", iae); } diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java index a5a3e972f..b659e63db 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java @@ -23,61 +23,61 @@ public class JdbcConfigurationTest { private static final JdbcConfigurationTestData[] VALID_URLs = new JdbcConfigurationTestData[] { - new JdbcConfigurationTestData("jdbc:ch://localhost"), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost"), - new JdbcConfigurationTestData("jdbc:clickhouse:http://localhost"), - new JdbcConfigurationTestData("jdbc:clickhouse:https://localhost") - .withExpectedConnectionURL("https://localhost:8443"), + new JdbcConfigurationTestData("jdbc:ch://localhost:8123") + .withExpectedConnectionURL("http://localhost:8123"), + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123") + .withExpectedConnectionURL("http://localhost:8123"), + new JdbcConfigurationTestData("jdbc:clickhouse:http://unknown-host.local:8443") + .withExpectedConnectionURL("http://unknown-host.local:8443"), + new JdbcConfigurationTestData("jdbc:clickhouse:http://localhost:8443") + .withExpectedConnectionURL("http://localhost:8443"), new JdbcConfigurationTestData("jdbc:clickhouse:https://localhost:8123") .withExpectedConnectionURL("https://localhost:8123"), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost") + new JdbcConfigurationTestData("jdbc:clickhouse:https://localhost:8123") + .withExpectedConnectionURL("https://localhost:8123"), + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8443") .withAdditionalConnectionParameters( Map.of(JdbcConfiguration.USE_SSL_PROP, "true")) .withExpectedConnectionURL("https://localhost:8443"), // ssl should not be passed to client - new JdbcConfigurationTestData("jdbc:clickhouse://[::1]") + new JdbcConfigurationTestData("jdbc:clickhouse://[::1]:8123") .withExpectedConnectionURL("http://[::1]:8123"), new JdbcConfigurationTestData("jdbc:clickhouse://[::1]:8123") .withExpectedConnectionURL("http://[::1]:8123"), new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8443") .withExpectedConnectionURL("http://localhost:8443"), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/database") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/database") .withAdditionalExpectedClientProperties( Map.of("database", "database")), new JdbcConfigurationTestData("jdbc:clickhouse://localhost:42/database") .withExpectedConnectionURL("http://localhost:42") .withAdditionalExpectedClientProperties( Map.of("database", "database")), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/data-base") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/data-base") .withAdditionalExpectedClientProperties( Map.of("database", "data-base")), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/data%20base") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/data%20base") .withAdditionalExpectedClientProperties( Map.of("database", "data base")), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/data%2Fbase") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/data%2Fbase") .withAdditionalExpectedClientProperties( Map.of("database", "data/base")), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/☺") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/☺") .withAdditionalExpectedClientProperties( Map.of("database", "☺")), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/db?custom_key1=val1&custom_key2=val2") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/db?custom_key1=val1&custom_key2=val2") .withAdditionalExpectedClientProperties( Map.of( "database", "db", "custom_key1", "val1", "custom_key2", "val2" )), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/db?custom_key1=val%201") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/db?custom_key1=val%201") .withAdditionalExpectedClientProperties( Map.of( "database", "db", "custom_key1", "val 1" )), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/?custom_key1=val1") - .withAdditionalExpectedClientProperties( - Map.of( - "custom_key1", "val1" - )), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost?custom_key1=val1") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/?custom_key1=val1") .withAdditionalExpectedClientProperties( Map.of( "custom_key1", "val1" @@ -94,12 +94,12 @@ public class JdbcConfigurationTest { Map.of( "custom_key1", "val1" )), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost?custom_key1=☺") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123?custom_key1=☺") .withAdditionalExpectedClientProperties( Map.of( "custom_key1", "☺" )), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost?custom_key1=val1,val2") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123?custom_key1=val1,val2") .withAdditionalExpectedClientProperties( Map.of( "custom_key1", "val1,val2" From 7879a7d1d767449a51af8887e1326304be7d0ffa Mon Sep 17 00:00:00 2001 From: Sergey Chernov Date: Mon, 23 Feb 2026 20:23:36 -0800 Subject: [PATCH 2/2] removed unused imports and duplicate tests --- .../java/com/clickhouse/jdbc/internal/JdbcConfiguration.java | 2 -- .../com/clickhouse/jdbc/internal/JdbcConfigurationTest.java | 3 --- 2 files changed, 5 deletions(-) diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java index c20801b3a..922931248 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java @@ -2,13 +2,11 @@ import com.clickhouse.client.api.Client; import com.clickhouse.client.api.ClientConfigProperties; -import com.clickhouse.client.api.http.ClickHouseHttpProto; import com.clickhouse.data.ClickHouseDataType; import com.clickhouse.jdbc.Driver; import com.clickhouse.jdbc.DriverProperties; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import org.apache.hc.client5.http.utils.URIUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java index b659e63db..bd4c5a0ce 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java @@ -2,7 +2,6 @@ import com.clickhouse.client.api.Client; import com.clickhouse.client.api.ClientConfigProperties; - import com.clickhouse.jdbc.DriverProperties; import org.testng.Assert; import org.testng.annotations.DataProvider; @@ -33,8 +32,6 @@ public class JdbcConfigurationTest { .withExpectedConnectionURL("http://localhost:8443"), new JdbcConfigurationTestData("jdbc:clickhouse:https://localhost:8123") .withExpectedConnectionURL("https://localhost:8123"), - new JdbcConfigurationTestData("jdbc:clickhouse:https://localhost:8123") - .withExpectedConnectionURL("https://localhost:8123"), new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8443") .withAdditionalConnectionParameters( Map.of(JdbcConfiguration.USE_SSL_PROP, "true"))