Skip to content

Commit e9e6b2b

Browse files
committed
fix(bigquery-jdbc): address PR review comments for createProxyOptions
1 parent 5fc36cf commit e9e6b2b

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

‎java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,22 +544,29 @@ public static <T> T withTracing(
544544
}
545545

546546
private static ProxyOptions createProxyOptions(Map<String, String> proxyProperties) {
547-
if (proxyProperties == null
548-
|| !proxyProperties.containsKey(BigQueryJdbcUrlUtility.PROXY_HOST_PROPERTY_NAME)
549-
|| !proxyProperties.containsKey(BigQueryJdbcUrlUtility.PROXY_PORT_PROPERTY_NAME)) {
547+
if (proxyProperties == null) {
550548
return null;
551549
}
552550

553551
final String host = proxyProperties.get(BigQueryJdbcUrlUtility.PROXY_HOST_PROPERTY_NAME);
554-
final int port =
555-
Integer.parseInt(proxyProperties.get(BigQueryJdbcUrlUtility.PROXY_PORT_PROPERTY_NAME));
552+
final String portStr = proxyProperties.get(BigQueryJdbcUrlUtility.PROXY_PORT_PROPERTY_NAME);
553+
if (host == null || host.isEmpty() || portStr == null || portStr.isEmpty()) {
554+
return null;
555+
}
556+
557+
int port;
558+
try {
559+
port = Integer.parseInt(portStr);
560+
} catch (NumberFormatException e) {
561+
throw new BigQueryJdbcRuntimeException("Invalid proxy port number: " + portStr, e);
562+
}
556563

557564
ProxySelector proxySelector =
558565
new ProxySelector() {
559566
@Override
560567
public List<Proxy> select(URI uri) {
561568
return Collections.singletonList(
562-
new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port)));
569+
new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(host, port)));
563570
}
564571

565572
@Override

0 commit comments

Comments
 (0)