Thread safety problem in java.net.ProxySelector

David Lloyd david.lloyd at redhat.com
Thu Sep 10 12:26:02 UTC 2020


The bug ID is https://bugs.openjdk.java.net/browse/JDK-8252996 .

On Wed, Sep 9, 2020 at 3:14 PM Chris Hegarty <chris.hegarty at oracle.com> wrote:
>
> 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
> >
>


-- 
- DML • he/him



More information about the net-dev mailing list