Skip to content

Commit af16234

Browse files
rm-gh-8Paul Hohensee
authored andcommitted
8373537: Migrate "test/jdk/com/sun/net/httpserver/" to null-safe "SimpleSSLContext" methods
Backport-of: 14c93b2
1 parent 39915a6 commit af16234

15 files changed

Lines changed: 30 additions & 43 deletions

test/jdk/com/sun/net/httpserver/HttpsParametersClientAuthTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public class HttpsParametersClientAuthTest {
8383
return t;
8484
};
8585

86+
private static final SSLContext serverSSLCtx = SimpleSSLContext.findSSLContext();
8687
/**
8788
* verifies default values of {@link HttpsParameters#setNeedClientAuth(boolean)}
8889
* and {@link HttpsParameters#setWantClientAuth(boolean)} methods
@@ -167,8 +168,6 @@ public void testWantClientAuth(final boolean initialNeedClientAuth) throws Excep
167168
public void testServerNeedClientAuth(final boolean presentClientCerts) throws Exception {
168169
// SSLContext which contains both the key and the trust material and will be used
169170
// by the server
170-
final SSLContext serverSSLCtx = new SimpleSSLContext().get();
171-
assertNotNull(serverSSLCtx, "could not create SSLContext");
172171
final HttpsConfigurator configurator = new HttpsConfigurator(serverSSLCtx) {
173172
@Override
174173
public void configure(final HttpsParameters params) {
@@ -275,8 +274,6 @@ public void configure(final HttpsParameters params) {
275274
public void testServerWantClientAuth(final boolean presentClientCerts) throws Exception {
276275
// SSLContext which contains both the key and the trust material and will be used
277276
// by the server
278-
final SSLContext serverSSLCtx = new SimpleSSLContext().get();
279-
assertNotNull(serverSSLCtx, "could not create SSLContext");
280277
final HttpsConfigurator configurator = new HttpsConfigurator(serverSSLCtx) {
281278
@Override
282279
public void configure(final HttpsParameters params) {

test/jdk/com/sun/net/httpserver/SANTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -61,7 +61,7 @@
6161
*/
6262
public class SANTest implements HttpServerAdapters {
6363

64-
static SSLContext ctx;
64+
private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
6565

6666
static HttpServer getHttpsServer(InetSocketAddress addr, Executor exec, SSLContext ctx) throws Exception {
6767
HttpsServer server = HttpsServer.create(addr, 0);
@@ -110,7 +110,6 @@ public static void main (String[] args) throws Exception {
110110
ExecutorService executor=null;
111111
try {
112112
System.out.print ("SANTest: ");
113-
ctx = new SimpleSSLContext().get();
114113
executor = Executors.newCachedThreadPool();
115114

116115
InetAddress l1 = InetAddress.getByName("::1");

test/jdk/com/sun/net/httpserver/SelCacheTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class SelCacheTest extends Test {
5959
private static final String TEMP_FILE_PREFIX =
6060
HttpServer.class.getPackageName() + '-' + SelCacheTest.class.getSimpleName() + '-';
6161

62-
static SSLContext ctx;
62+
private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
6363

6464
public static void main(String[] args) throws Exception {
6565
HttpServer s1 = null;
@@ -84,7 +84,6 @@ public static void main(String[] args) throws Exception {
8484
executor = Executors.newCachedThreadPool();
8585
s1.setExecutor(executor);
8686
s2.setExecutor(executor);
87-
ctx = new SimpleSSLContext().get();
8887
s2.setHttpsConfigurator(new HttpsConfigurator(ctx));
8988
s1.start();
9089
s2.start();

test/jdk/com/sun/net/httpserver/Test1.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class Test1 extends Test {
6969
private static final String TEMP_FILE_PREFIX =
7070
HttpServer.class.getPackageName() + '-' + Test1.class.getSimpleName() + '-';
7171

72-
static SSLContext ctx;
72+
private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
7373

7474
public static void main (String[] args) throws Exception {
7575
HttpServer s1 = null;
@@ -94,7 +94,6 @@ public static void main (String[] args) throws Exception {
9494
executor = Executors.newCachedThreadPool();
9595
s1.setExecutor (executor);
9696
s2.setExecutor (executor);
97-
ctx = new SimpleSSLContext().get();
9897
s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
9998
s1.start();
10099
s2.start();

test/jdk/com/sun/net/httpserver/Test12.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class Test12 extends Test {
5656
private static final String TEMP_FILE_PREFIX =
5757
HttpServer.class.getPackageName() + '-' + Test12.class.getSimpleName() + '-';
5858

59-
static SSLContext ctx;
59+
private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
6060

6161
public static void main (String[] args) throws Exception {
6262
HttpServer s1 = null;
@@ -77,7 +77,6 @@ public static void main (String[] args) throws Exception {
7777
HttpContext c2 = s2.createContext ("/", h);
7878
s1.setExecutor (executor);
7979
s2.setExecutor (executor);
80-
ctx = new SimpleSSLContext().get();
8180
s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
8281
s1.start();
8382
s2.start();

test/jdk/com/sun/net/httpserver/Test13.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class Test13 extends Test {
5959
private static final String TEMP_FILE_PREFIX =
6060
HttpServer.class.getPackageName() + '-' + Test13.class.getSimpleName() + '-';
6161

62-
static SSLContext ctx;
62+
private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
6363

6464
final static int NUM = 32; // was 32
6565

@@ -87,7 +87,6 @@ public static void main (String[] args) throws Exception {
8787
executor = Executors.newCachedThreadPool();
8888
s1.setExecutor (executor);
8989
s2.setExecutor (executor);
90-
ctx = new SimpleSSLContext().get();
9190
s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
9291
s1.start();
9392
s2.start();

test/jdk/com/sun/net/httpserver/Test6a.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* questions.
2222
*/
2323

24-
/**
24+
/*
2525
* @test
2626
* @bug 6270015
2727
* @library /test/lib
@@ -54,7 +54,7 @@ public static void main (String[] args) throws Exception {
5454
HttpsServer server = HttpsServer.create (addr, 0);
5555
HttpContext ctx = server.createContext ("/test", handler);
5656
ExecutorService executor = Executors.newCachedThreadPool();
57-
SSLContext ssl = new SimpleSSLContext().get();
57+
SSLContext ssl = SimpleSSLContext.findSSLContext();
5858
server.setExecutor (executor);
5959
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
6060
server.start ();

test/jdk/com/sun/net/httpserver/Test7a.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static void main (String[] args) throws Exception {
5858
HttpsServer server = HttpsServer.create (addr, 0);
5959
HttpContext ctx = server.createContext ("/test", handler);
6060
ExecutorService executor = Executors.newCachedThreadPool();
61-
SSLContext ssl = new SimpleSSLContext().get();
61+
SSLContext ssl = SimpleSSLContext.findSSLContext();
6262
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
6363
server.setExecutor (executor);
6464
server.start ();

test/jdk/com/sun/net/httpserver/Test8a.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -61,7 +61,7 @@ public static void main (String[] args) throws Exception {
6161
server = HttpsServer.create (addr, 0);
6262
HttpContext ctx = server.createContext ("/test", handler);
6363
executor = Executors.newCachedThreadPool();
64-
SSLContext ssl = new SimpleSSLContext().get();
64+
SSLContext ssl = SimpleSSLContext.findSSLContext();
6565
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
6666
server.setExecutor (executor);
6767
server.start ();

test/jdk/com/sun/net/httpserver/Test9.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class Test9 extends Test {
5858
private static final String TEMP_FILE_PREFIX =
5959
HttpServer.class.getPackageName() + '-' + Test9.class.getSimpleName() + '-';
6060

61-
static SSLContext ctx;
61+
private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
6262
static volatile boolean error = false;
6363

6464
public static void main (String[] args) throws Exception {
@@ -83,7 +83,6 @@ public static void main (String[] args) throws Exception {
8383
executor = Executors.newCachedThreadPool();
8484
s1.setExecutor (executor);
8585
s2.setExecutor (executor);
86-
ctx = new SimpleSSLContext().get();
8786
s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
8887
s1.start();
8988
s2.start();

0 commit comments

Comments
 (0)