Thread safety problem in java.net.ProxySelector
Chris Hegarty
chris.hegarty at oracle.com
Wed Sep 9 15:42:32 UTC 2020
Seems like a bug. Can you please file an issue for it.
Thanks,
-Chris.
> On 2 Sep 2020, at 14:16, David Lloyd <david.lloyd at redhat.com> wrote:
>
> The default proxy selector field in java.net.ProxySelector is
> essentially a global variable with no thread safety measures taken to
> ensure that accesses are valid. Anecdotally, a symptom of this bug
> *may* be that the field appears `null` after assignment (based on an
> IRC discussion with a confused user).
>
> Here's the trivial fix:
>
> diff --git a/src/java.base/share/classes/java/net/ProxySelector.java
> b/src/java.base/share/classes/java/net/ProxySelector.java
> index c1e97ecc981..e52c888f755 100644
> --- a/src/java.base/share/classes/java/net/ProxySelector.java
> +++ b/src/java.base/share/classes/java/net/ProxySelector.java
> @@ -65,7 +65,7 @@ public abstract class ProxySelector {
> *
> * @see #setDefault(ProxySelector)
> */
> - private static ProxySelector theProxySelector;
> + private static volatile ProxySelector theProxySelector;
>
> static {
> try {
>
>
> --
> - DML • he/him
>
More information about the net-dev
mailing list