Skip to content

Commit 064f3cc

Browse files
committed
fixed potential NPE and class cast exception
1 parent 0896eac commit 064f3cc

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
11971197
Integer retry = (Integer) configuration.get(ClientConfigProperties.RETRY_ON_FAILURE.getKey());
11981198
final int maxRetries = retry == null ? 0 : retry;
11991199

1200-
settings.setOption(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey(), format.name());
1200+
settings.setOption(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey(), format);
12011201
final InsertSettings finalSettings = new InsertSettings(buildRequestSettings(settings.getAllSettings()));
12021202
Supplier<InsertResponse> supplier = () -> {
12031203
long startTime = System.nanoTime();
@@ -1400,7 +1400,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
14001400
throw new IllegalArgumentException("Buffer size must be greater than 0");
14011401
}
14021402

1403-
settings.setOption(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey(), format.name());
1403+
settings.setOption(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey(), format);
14041404
final InsertSettings finalSettings = new InsertSettings(buildRequestSettings(settings.getAllSettings()));
14051405

14061406
StringBuilder sqlStmt = new StringBuilder("INSERT INTO ").append(tableName);

client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.clickhouse.client.api.enums.ProxyType;
1515
import com.clickhouse.client.api.http.ClickHouseHttpProto;
1616
import com.clickhouse.client.api.transport.Endpoint;
17+
import com.clickhouse.data.ClickHouseFormat;
1718
import net.jpountz.lz4.LZ4Factory;
1819
import org.apache.hc.client5.http.ConnectTimeoutException;
1920
import org.apache.hc.client5.http.classic.methods.HttpPost;
@@ -450,13 +451,13 @@ private void addHeaders(HttpPost req, Map<String, Object> requestConfig) {
450451
addHeader(
451452
req,
452453
ClickHouseHttpProto.HEADER_FORMAT,
453-
requestConfig.get(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey()));
454+
((ClickHouseFormat) requestConfig.get(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey())).name());
454455
}
455456
if (requestConfig.containsKey(ClientConfigProperties.QUERY_ID.getKey())) {
456457
addHeader(
457458
req,
458459
ClickHouseHttpProto.HEADER_QUERY_ID,
459-
requestConfig.get(ClientConfigProperties.QUERY_ID.getKey()));
460+
(String) requestConfig.get(ClientConfigProperties.QUERY_ID.getKey()));
460461
}
461462
addHeader(
462463
req,
@@ -758,22 +759,22 @@ public void close() {
758759
}
759760

760761
private static <T> void addHeader(HttpRequest req, String headerName,
761-
T value)
762+
String value)
762763
{
763764
if (value == null) {
764765
return;
765766
}
766-
String tString = value.toString();
767-
if (tString == null || tString.trim().isEmpty()) {
767+
768+
if (value.trim().isEmpty()) {
768769
return;
769770
}
770-
if (PATTERN_HEADER_VALUE_ASCII.matcher(tString).matches()) {
771-
req.addHeader(headerName, tString);
771+
if (PATTERN_HEADER_VALUE_ASCII.matcher(value).matches()) {
772+
req.addHeader(headerName, value);
772773
} else {
773774
try {
774775
req.addHeader(
775776
headerName + "*",
776-
"UTF-8''" + URLEncoder.encode(tString, StandardCharsets.UTF_8.name()));
777+
"UTF-8''" + URLEncoder.encode(value, StandardCharsets.UTF_8.name()));
777778
} catch (UnsupportedEncodingException e) {
778779
throw new ClientException("Failed to convert string to UTF8" , e);
779780
}

0 commit comments

Comments
 (0)