diff --git a/test/jdk/com/sun/net/httpserver/HttpsParametersClientAuthTest.java b/test/jdk/com/sun/net/httpserver/HttpsParametersClientAuthTest.java index 37ec2701e07..5514b5da689 100644 --- a/test/jdk/com/sun/net/httpserver/HttpsParametersClientAuthTest.java +++ b/test/jdk/com/sun/net/httpserver/HttpsParametersClientAuthTest.java @@ -84,6 +84,7 @@ public class HttpsParametersClientAuthTest { return t; }; + private static final SSLContext serverSSLCtx = SimpleSSLContext.findSSLContext(); /** * verifies default values of {@link HttpsParameters#setNeedClientAuth(boolean)} * and {@link HttpsParameters#setWantClientAuth(boolean)} methods @@ -168,8 +169,6 @@ public class HttpsParametersClientAuthTest { public void testServerNeedClientAuth(final boolean presentClientCerts) throws Exception { // SSLContext which contains both the key and the trust material and will be used // by the server - final SSLContext serverSSLCtx = new SimpleSSLContext().get(); - assertNotNull(serverSSLCtx, "could not create SSLContext"); final HttpsConfigurator configurator = new HttpsConfigurator(serverSSLCtx) { @Override public void configure(final HttpsParameters params) { @@ -276,8 +275,6 @@ public class HttpsParametersClientAuthTest { public void testServerWantClientAuth(final boolean presentClientCerts) throws Exception { // SSLContext which contains both the key and the trust material and will be used // by the server - final SSLContext serverSSLCtx = new SimpleSSLContext().get(); - assertNotNull(serverSSLCtx, "could not create SSLContext"); final HttpsConfigurator configurator = new HttpsConfigurator(serverSSLCtx) { @Override public void configure(final HttpsParameters params) { diff --git a/test/jdk/com/sun/net/httpserver/SANTest.java b/test/jdk/com/sun/net/httpserver/SANTest.java index d35a590931d..99612376589 100644 --- a/test/jdk/com/sun/net/httpserver/SANTest.java +++ b/test/jdk/com/sun/net/httpserver/SANTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -73,7 +73,7 @@ import jdk.httpclient.test.lib.http2.Http2TestServer; */ public class SANTest implements HttpServerAdapters { - static SSLContext ctx; + private static final SSLContext ctx = SimpleSSLContext.findSSLContext(); static HttpServer getHttpsServer(InetSocketAddress addr, Executor exec, SSLContext ctx) throws Exception { HttpsServer server = HttpsServer.create(addr, 0); @@ -122,7 +122,6 @@ public class SANTest implements HttpServerAdapters { ExecutorService executor=null; try { System.out.print ("SANTest: "); - ctx = new SimpleSSLContext().get(); executor = Executors.newCachedThreadPool(); InetAddress l1 = InetAddress.getByName("::1"); diff --git a/test/jdk/com/sun/net/httpserver/SelCacheTest.java b/test/jdk/com/sun/net/httpserver/SelCacheTest.java index 1399b65532b..8410aa0578a 100644 --- a/test/jdk/com/sun/net/httpserver/SelCacheTest.java +++ b/test/jdk/com/sun/net/httpserver/SelCacheTest.java @@ -59,7 +59,7 @@ public class SelCacheTest extends Test { private static final String TEMP_FILE_PREFIX = HttpServer.class.getPackageName() + '-' + SelCacheTest.class.getSimpleName() + '-'; - static SSLContext ctx; + private static final SSLContext ctx = SimpleSSLContext.findSSLContext(); public static void main(String[] args) throws Exception { HttpServer s1 = null; @@ -84,7 +84,6 @@ public class SelCacheTest extends Test { executor = Executors.newCachedThreadPool(); s1.setExecutor(executor); s2.setExecutor(executor); - ctx = new SimpleSSLContext().get(); s2.setHttpsConfigurator(new HttpsConfigurator(ctx)); s1.start(); s2.start(); diff --git a/test/jdk/com/sun/net/httpserver/Test1.java b/test/jdk/com/sun/net/httpserver/Test1.java index 32bab4d9178..858c0a20f55 100644 --- a/test/jdk/com/sun/net/httpserver/Test1.java +++ b/test/jdk/com/sun/net/httpserver/Test1.java @@ -69,7 +69,7 @@ public class Test1 extends Test { private static final String TEMP_FILE_PREFIX = HttpServer.class.getPackageName() + '-' + Test1.class.getSimpleName() + '-'; - static SSLContext ctx; + private static final SSLContext ctx = SimpleSSLContext.findSSLContext(); public static void main (String[] args) throws Exception { HttpServer s1 = null; @@ -94,7 +94,6 @@ public class Test1 extends Test { executor = Executors.newCachedThreadPool(); s1.setExecutor (executor); s2.setExecutor (executor); - ctx = new SimpleSSLContext().get(); s2.setHttpsConfigurator(new HttpsConfigurator (ctx)); s1.start(); s2.start(); diff --git a/test/jdk/com/sun/net/httpserver/Test12.java b/test/jdk/com/sun/net/httpserver/Test12.java index 2a0ee1fc0a4..ac11e92d44e 100644 --- a/test/jdk/com/sun/net/httpserver/Test12.java +++ b/test/jdk/com/sun/net/httpserver/Test12.java @@ -56,7 +56,7 @@ public class Test12 extends Test { private static final String TEMP_FILE_PREFIX = HttpServer.class.getPackageName() + '-' + Test12.class.getSimpleName() + '-'; - static SSLContext ctx; + private static final SSLContext ctx = SimpleSSLContext.findSSLContext(); public static void main (String[] args) throws Exception { HttpServer s1 = null; @@ -77,7 +77,6 @@ public class Test12 extends Test { HttpContext c2 = s2.createContext ("/", h); s1.setExecutor (executor); s2.setExecutor (executor); - ctx = new SimpleSSLContext().get(); s2.setHttpsConfigurator(new HttpsConfigurator (ctx)); s1.start(); s2.start(); diff --git a/test/jdk/com/sun/net/httpserver/Test13.java b/test/jdk/com/sun/net/httpserver/Test13.java index ead3ff95acd..0401dbce5a8 100644 --- a/test/jdk/com/sun/net/httpserver/Test13.java +++ b/test/jdk/com/sun/net/httpserver/Test13.java @@ -59,7 +59,7 @@ public class Test13 extends Test { private static final String TEMP_FILE_PREFIX = HttpServer.class.getPackageName() + '-' + Test13.class.getSimpleName() + '-'; - static SSLContext ctx; + private static final SSLContext ctx = SimpleSSLContext.findSSLContext(); final static int NUM = 32; // was 32 @@ -87,7 +87,6 @@ public class Test13 extends Test { executor = Executors.newCachedThreadPool(); s1.setExecutor (executor); s2.setExecutor (executor); - ctx = new SimpleSSLContext().get(); s2.setHttpsConfigurator(new HttpsConfigurator (ctx)); s1.start(); s2.start(); diff --git a/test/jdk/com/sun/net/httpserver/Test6a.java b/test/jdk/com/sun/net/httpserver/Test6a.java index 676edeb7b60..56614078cfe 100644 --- a/test/jdk/com/sun/net/httpserver/Test6a.java +++ b/test/jdk/com/sun/net/httpserver/Test6a.java @@ -21,7 +21,7 @@ * questions. */ -/** +/* * @test * @bug 6270015 * @library /test/lib @@ -55,7 +55,7 @@ public class Test6a extends Test { HttpsServer server = HttpsServer.create (addr, 0); HttpContext ctx = server.createContext ("/test", handler); ExecutorService executor = Executors.newCachedThreadPool(); - SSLContext ssl = new SimpleSSLContext().get(); + SSLContext ssl = SimpleSSLContext.findSSLContext(); server.setExecutor (executor); server.setHttpsConfigurator(new HttpsConfigurator (ssl)); server.start (); diff --git a/test/jdk/com/sun/net/httpserver/Test7a.java b/test/jdk/com/sun/net/httpserver/Test7a.java index 90c0615972e..8bda4ae8348 100644 --- a/test/jdk/com/sun/net/httpserver/Test7a.java +++ b/test/jdk/com/sun/net/httpserver/Test7a.java @@ -59,7 +59,7 @@ public class Test7a extends Test { HttpsServer server = HttpsServer.create (addr, 0); HttpContext ctx = server.createContext ("/test", handler); ExecutorService executor = Executors.newCachedThreadPool(); - SSLContext ssl = new SimpleSSLContext().get(); + SSLContext ssl = SimpleSSLContext.findSSLContext(); server.setHttpsConfigurator(new HttpsConfigurator (ssl)); server.setExecutor (executor); server.start (); diff --git a/test/jdk/com/sun/net/httpserver/Test8a.java b/test/jdk/com/sun/net/httpserver/Test8a.java index 6c642f7c22a..67f9c93172a 100644 --- a/test/jdk/com/sun/net/httpserver/Test8a.java +++ b/test/jdk/com/sun/net/httpserver/Test8a.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -61,7 +61,7 @@ public class Test8a extends Test { server = HttpsServer.create (addr, 0); HttpContext ctx = server.createContext ("/test", handler); executor = Executors.newCachedThreadPool(); - SSLContext ssl = new SimpleSSLContext().get(); + SSLContext ssl = SimpleSSLContext.findSSLContext(); server.setHttpsConfigurator(new HttpsConfigurator (ssl)); server.setExecutor (executor); server.start (); diff --git a/test/jdk/com/sun/net/httpserver/Test9.java b/test/jdk/com/sun/net/httpserver/Test9.java index 6051de96596..8281089c232 100644 --- a/test/jdk/com/sun/net/httpserver/Test9.java +++ b/test/jdk/com/sun/net/httpserver/Test9.java @@ -58,7 +58,7 @@ public class Test9 extends Test { private static final String TEMP_FILE_PREFIX = HttpServer.class.getPackageName() + '-' + Test9.class.getSimpleName() + '-'; - static SSLContext ctx; + private static final SSLContext ctx = SimpleSSLContext.findSSLContext(); static volatile boolean error = false; public static void main (String[] args) throws Exception { @@ -83,7 +83,6 @@ public class Test9 extends Test { executor = Executors.newCachedThreadPool(); s1.setExecutor (executor); s2.setExecutor (executor); - ctx = new SimpleSSLContext().get(); s2.setHttpsConfigurator(new HttpsConfigurator (ctx)); s1.start(); s2.start(); diff --git a/test/jdk/com/sun/net/httpserver/Test9a.java b/test/jdk/com/sun/net/httpserver/Test9a.java index 85acfd26518..56fbf9953a3 100644 --- a/test/jdk/com/sun/net/httpserver/Test9a.java +++ b/test/jdk/com/sun/net/httpserver/Test9a.java @@ -56,8 +56,8 @@ public class Test9a extends Test { private static final String TEMP_FILE_PREFIX = HttpServer.class.getPackageName() + '-' + Test9a.class.getSimpleName() + '-'; - static SSLContext serverCtx; - static volatile SSLContext clientCtx = null; + private static final SSLContext serverCtx = SimpleSSLContext.findSSLContext(); + private static final SSLContext clientCtx = SimpleSSLContext.findSSLContext(); static volatile boolean error = false; public static void main (String[] args) throws Exception { @@ -76,8 +76,6 @@ public class Test9a extends Test { HttpContext c1 = server.createContext ("/", h); executor = Executors.newCachedThreadPool(); server.setExecutor (executor); - serverCtx = new SimpleSSLContext().get(); - clientCtx = new SimpleSSLContext().get(); server.setHttpsConfigurator(new HttpsConfigurator (serverCtx)); server.start(); diff --git a/test/jdk/com/sun/net/httpserver/bugs/HandlerConnectionClose.java b/test/jdk/com/sun/net/httpserver/bugs/HandlerConnectionClose.java index 89839e462c5..372e941904e 100644 --- a/test/jdk/com/sun/net/httpserver/bugs/HandlerConnectionClose.java +++ b/test/jdk/com/sun/net/httpserver/bugs/HandlerConnectionClose.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -63,7 +63,7 @@ public class HandlerConnectionClose { static final int ONEK = 1024; static final long POST_SIZE = ONEK * 1L; - SSLContext sslContext; + private static final SSLContext sslContext = SimpleSSLContext.findSSLContext(); Logger logger; void test(String[] args) throws Exception { @@ -77,7 +77,6 @@ public class HandlerConnectionClose } finally { httpServer.stop(0); } - sslContext = new SimpleSSLContext().get(); HttpServer httpsServer = startHttpServer("https"); try { testHttpURLConnection(httpsServer, "https","/close/legacy/https/chunked"); diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerAlertTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerAlertTest.java index 2ba54d61ada..07433bdbb2a 100644 --- a/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerAlertTest.java +++ b/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerAlertTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -59,7 +59,11 @@ public class HttpsServerAlertTest { static final boolean ENABLE_LOGGING = true; static final Logger LOGGER = Logger.getLogger("com.sun.net.httpserver"); - SSLContext sslContext; + private static final SSLContext sslContext = SimpleSSLContext.findSSLContext(); + + static { + SSLContext.setDefault(sslContext); + } @BeforeTest public void setup() throws IOException { @@ -69,8 +73,6 @@ public class HttpsServerAlertTest { ch.setLevel(Level.ALL); LOGGER.addHandler(ch); } - sslContext = new SimpleSSLContext().get(); - SSLContext.setDefault(sslContext); } @Test diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerTest.java index 2227c4cd437..783f159f5c1 100644 --- a/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerTest.java +++ b/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,7 +40,6 @@ import java.net.http.HttpRequest; import java.net.http.HttpResponse.BodyHandlers; import java.nio.charset.StandardCharsets; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.Logger; @@ -67,7 +66,11 @@ public class HttpsServerTest { static final boolean ENABLE_LOGGING = true; static final Logger LOGGER = Logger.getLogger("com.sun.net.httpserver"); - SSLContext sslContext; + private static final SSLContext sslContext = SimpleSSLContext.findSSLContext(); + + static { + SSLContext.setDefault(sslContext); + } @BeforeTest public void setup() throws IOException { @@ -77,8 +80,6 @@ public class HttpsServerTest { ch.setLevel(Level.ALL); LOGGER.addHandler(ch); } - sslContext = new SimpleSSLContext().get(); - SSLContext.setDefault(sslContext); } @Test diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/MaxRequestTimeTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/MaxRequestTimeTest.java index c972f87dc18..695843de8b0 100644 --- a/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/MaxRequestTimeTest.java +++ b/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/MaxRequestTimeTest.java @@ -78,7 +78,7 @@ public class MaxRequestTimeTest { static final String LOOPBACK_ADDR = InetAddress.getLoopbackAddress().getHostAddress(); static final AtomicInteger PORT = new AtomicInteger(); - static SSLContext sslContext; + private static final SSLContext sslContext = SimpleSSLContext.findSSLContext(); @BeforeTest public void setup() throws IOException { @@ -86,10 +86,6 @@ public class MaxRequestTimeTest { FileUtils.deleteFileTreeWithRetry(TEST_DIR); } Files.createDirectories(TEST_DIR); - - sslContext = new SimpleSSLContext().get(); - if (sslContext == null) - throw new AssertionError("Unexpected null sslContext"); } @Test