From 5ae627e2f7767b592b41d957eac72111404da358 Mon Sep 17 00:00:00 2001 From: Dimitri Tenenbaum Date: Fri, 7 Jul 2023 22:39:39 +0200 Subject: [PATCH 1/7] Fixed race condition Fixed race condition, see: https://github.com/eclipse-ee4j/jersey/issues/5358 --- .../glassfish/jersey/client/internal/HttpUrlConnector.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java b/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java index 3e29e2be8a..41d4d09c83 100644 --- a/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java +++ b/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java @@ -312,11 +312,7 @@ protected void secureConnection(final JerseyClient client, final HttpURLConnecti if (verifier != null) { suc.setHostnameVerifier(verifier); } - - if (DEFAULT_SSL_SOCKET_FACTORY.get() == suc.getSSLSocketFactory()) { - // indicates that the custom socket factory was not set - suc.setSSLSocketFactory(sslSocketFactory.get()); - } + suc.setSSLSocketFactory(sslSocketFactory.get()); } } From b6b9f19a72c0d9df124aad52a93b23c3e0435aca Mon Sep 17 00:00:00 2001 From: Dimitri Tenenbaum Date: Thu, 5 Oct 2023 15:34:34 +0000 Subject: [PATCH 2/7] revert change --- .../glassfish/jersey/client/internal/HttpUrlConnector.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java b/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java index a57adddf99..1534976110 100644 --- a/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java +++ b/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java @@ -307,7 +307,12 @@ protected void secureConnection(final JerseyClient client, final HttpURLConnecti if (verifier != null) { suc.setHostnameVerifier(verifier); } - suc.setSSLSocketFactory(sslSocketFactory.get()); + + if (DEFAULT_SSL_SOCKET_FACTORY.get() == suc.getSSLSocketFactory()) { + // indicates that the custom socket factory was not set + suc.setSSLSocketFactory(sslSocketFactory.get()); + } + } } From 8637637e551638b60718cb111a77d77cccd51765 Mon Sep 17 00:00:00 2001 From: Dimitri Tenenbaum Date: Thu, 5 Oct 2023 15:36:38 +0000 Subject: [PATCH 3/7] race condition fix: synchronized getConnection() --- .../org/glassfish/jersey/client/HttpUrlConnectorProvider.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core-client/src/main/java/org/glassfish/jersey/client/HttpUrlConnectorProvider.java b/core-client/src/main/java/org/glassfish/jersey/client/HttpUrlConnectorProvider.java index 25a6d78cf5..3104f22dc1 100644 --- a/core-client/src/main/java/org/glassfish/jersey/client/HttpUrlConnectorProvider.java +++ b/core-client/src/main/java/org/glassfish/jersey/client/HttpUrlConnectorProvider.java @@ -283,7 +283,9 @@ public interface ConnectionFactory { * @throws java.io.IOException in case the connection cannot be provided. */ default HttpURLConnection getConnection(URL url, Proxy proxy) throws IOException { - return (proxy == null) ? getConnection(url) : (HttpURLConnection) url.openConnection(proxy); + synchronized (this){ + return (proxy == null) ? getConnection(url) : (HttpURLConnection) url.openConnection(proxy); + } } } From 37baec59278ba68739c1247bb76be3be2b9d0e5a Mon Sep 17 00:00:00 2001 From: Dimitri Tenenbaum Date: Thu, 5 Oct 2023 15:38:53 +0000 Subject: [PATCH 4/7] fixed style issue --- .../org/glassfish/jersey/client/internal/HttpUrlConnector.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java b/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java index 1534976110..97cd9bf0bf 100644 --- a/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java +++ b/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java @@ -311,8 +311,7 @@ protected void secureConnection(final JerseyClient client, final HttpURLConnecti if (DEFAULT_SSL_SOCKET_FACTORY.get() == suc.getSSLSocketFactory()) { // indicates that the custom socket factory was not set suc.setSSLSocketFactory(sslSocketFactory.get()); - } - + } } } From fe93d4241a675472c513742da7028a1d9f64fc81 Mon Sep 17 00:00:00 2001 From: Dimitri Tenenbaum Date: Thu, 5 Oct 2023 17:36:37 +0000 Subject: [PATCH 5/7] fixed checkstyle issue --- .../org/glassfish/jersey/client/internal/HttpUrlConnector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java b/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java index 97cd9bf0bf..9f951ce43f 100644 --- a/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java +++ b/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java @@ -311,7 +311,7 @@ protected void secureConnection(final JerseyClient client, final HttpURLConnecti if (DEFAULT_SSL_SOCKET_FACTORY.get() == suc.getSSLSocketFactory()) { // indicates that the custom socket factory was not set suc.setSSLSocketFactory(sslSocketFactory.get()); - } + } } } From f5c9f5fff911533342af7de9318528962aa166f3 Mon Sep 17 00:00:00 2001 From: Dimitri Tenenbaum Date: Thu, 5 Oct 2023 18:18:32 +0000 Subject: [PATCH 6/7] fixed style issue --- .../org/glassfish/jersey/client/internal/HttpUrlConnector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java b/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java index 9f951ce43f..afea5f0bb8 100644 --- a/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java +++ b/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java @@ -311,7 +311,7 @@ protected void secureConnection(final JerseyClient client, final HttpURLConnecti if (DEFAULT_SSL_SOCKET_FACTORY.get() == suc.getSSLSocketFactory()) { // indicates that the custom socket factory was not set suc.setSSLSocketFactory(sslSocketFactory.get()); - } + } } } From ca3fd0d7d29d4d0b5cc7c284f0cf8d6dfc79533d Mon Sep 17 00:00:00 2001 From: Dimitri Tenenbaum Date: Thu, 5 Oct 2023 18:33:32 +0000 Subject: [PATCH 7/7] changed Copyright year to 2029 --- .../org/glassfish/jersey/client/HttpUrlConnectorProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-client/src/main/java/org/glassfish/jersey/client/HttpUrlConnectorProvider.java b/core-client/src/main/java/org/glassfish/jersey/client/HttpUrlConnectorProvider.java index 3104f22dc1..00ffd75411 100644 --- a/core-client/src/main/java/org/glassfish/jersey/client/HttpUrlConnectorProvider.java +++ b/core-client/src/main/java/org/glassfish/jersey/client/HttpUrlConnectorProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at