--- old/src/share/classes/java/net/URL.java 2014-07-07 12:44:54.155309318 +0200 +++ new/src/share/classes/java/net/URL.java 2014-07-07 12:44:54.065310938 +0200 @@ -1071,7 +1071,7 @@ /** * The URLStreamHandler factory. */ - static URLStreamHandlerFactory factory; + private static volatile URLStreamHandlerFactory factory; /** * Sets an application's {@code URLStreamHandlerFactory}. @@ -1106,6 +1106,7 @@ security.checkSetFactory(); } handlers.clear(); + // safe publication of URLStreamHandlerFactory with volatile write factory = fac; } } @@ -1127,9 +1128,11 @@ boolean checkedWithFactory = false; - // Use the factory (if any) - if (factory != null) { - handler = factory.createURLStreamHandler(protocol); + // Use the factory (if any). Volatile read makes + // URLStreamHandlerFactory appear fully initialized to current thread. + URLStreamHandlerFactory fac = factory; + if (fac != null) { + handler = fac.createURLStreamHandler(protocol); checkedWithFactory = true; } @@ -1193,8 +1196,8 @@ // Check with factory if another thread set a // factory since our last check - if (!checkedWithFactory && factory != null) { - handler2 = factory.createURLStreamHandler(protocol); + if (!checkedWithFactory && (fac = factory) != null) { + handler2 = fac.createURLStreamHandler(protocol); } if (handler2 != null) {