< prev index next >

src/java.base/share/classes/java/net/URL.java

Print this page
*** 43,10 ***
--- 43,11 ---
  import java.util.ServiceConfigurationError;
  import java.util.ServiceLoader;
  
  import jdk.internal.access.JavaNetURLAccess;
  import jdk.internal.access.SharedSecrets;
+ import jdk.internal.misc.Gate;
  import jdk.internal.misc.VM;
  import sun.net.util.IPAddressUtil;
  import sun.security.util.SecurityConstants;
  import sun.security.action.GetPropertyAction;
  

*** 1340,19 ***
                  return n;
              }
          };
      }
  
!     // Thread-local gate to prevent recursive provider lookups
!     private static ThreadLocal<Object> gate = new ThreadLocal<>();
  
      @SuppressWarnings("removal")
      private static URLStreamHandler lookupViaProviders(final String protocol) {
!         if (gate.get() != null)
              throw new Error("Circular loading of URL stream handler providers detected");
- 
-         gate.set(gate);
          try {
              return AccessController.doPrivileged(
                  new PrivilegedAction<>() {
                      public URLStreamHandler run() {
                          Iterator<URLStreamHandlerProvider> itr = providers();
--- 1341,17 ---
                  return n;
              }
          };
      }
  
!     // gate to prevent recursive provider lookups
!     private static final Gate LOOKUP_GATE = Gate.create();
  
      @SuppressWarnings("removal")
      private static URLStreamHandler lookupViaProviders(final String protocol) {
!         if (!LOOKUP_GATE.tryEnter())
              throw new Error("Circular loading of URL stream handler providers detected");
          try {
              return AccessController.doPrivileged(
                  new PrivilegedAction<>() {
                      public URLStreamHandler run() {
                          Iterator<URLStreamHandlerProvider> itr = providers();

*** 1364,11 ***
                          }
                          return null;
                      }
                  });
          } finally {
!             gate.set(null);
          }
      }
  
      /**
       * Returns the protocol in lower case. Special cases known protocols
--- 1363,11 ---
                          }
                          return null;
                      }
                  });
          } finally {
!             LOOKUP_GATE.exit();
          }
      }
  
      /**
       * Returns the protocol in lower case. Special cases known protocols
< prev index next >