--- old/src/java.base/share/classes/java/net/URL.java 2018-11-21 12:57:40.306447781 +0000 +++ new/src/java.base/share/classes/java/net/URL.java 2018-11-21 12:57:39.866447781 +0000 @@ -1393,39 +1393,39 @@ } } + if (handler == null) { + // Try the built-in protocol handler + handler = defaultFactory.createURLStreamHandler(protocol); + } + synchronized (streamHandlerLock) { - if (handler == null) { - // Try the built-in protocol handler - handler = defaultFactory.createURLStreamHandler(protocol); - } else { - URLStreamHandler handler2 = null; - - // Check again with hashtable just in case another - // thread created a handler since we last checked - handler2 = handlers.get(protocol); - - if (handler2 != null) { - return handler2; - } - - // Check with factory if another thread set a - // factory since our last check - if (!checkedWithFactory && (fac = factory) != null) { - handler2 = fac.createURLStreamHandler(protocol); - } - - if (handler2 != null) { - // The handler from the factory must be given more - // importance. Discard the default handler that - // this thread created. - handler = handler2; - } + URLStreamHandler handler2 = null; + + // Check again with hashtable just in case another + // thread created a handler since we last checked + handler2 = handlers.get(protocol); + + if (handler2 != null) { + return handler2; } - // Insert this handler into the hashtable - if (handler != null) { - handlers.put(protocol, handler); + // Check with factory if another thread set a + // factory since our last check + if (!checkedWithFactory && (fac = factory) != null) { + handler2 = fac.createURLStreamHandler(protocol); } + + if (handler2 != null) { + // The handler from the factory must be given more + // importance. Discard the default handler that + // this thread created. + handler = handler2; + } + } + + // Insert this handler into the hashtable + if (handler != null) { + handlers.put(protocol, handler); } return handler;