Skip to content

Commit 14c93b2

Browse files
committed
8373537: Migrate "test/jdk/com/sun/net/httpserver/" to null-safe "SimpleSSLContext" methods
Reviewed-by: dfuchs
1 parent 53e77d2 commit 14c93b2

File tree

15 files changed

+30
-43
lines changed

15 files changed

+30
-43
lines changed

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

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

87+
private static final SSLContext serverSSLCtx = SimpleSSLContext.findSSLContext();
8788
/**
8889
* verifies default values of {@link HttpsParameters#setNeedClientAuth(boolean)}
8990
* and {@link HttpsParameters#setWantClientAuth(boolean)} methods
@@ -168,8 +169,6 @@ public void testWantClientAuth(final boolean initialNeedClientAuth) throws Excep
168169
public void testServerNeedClientAuth(final boolean presentClientCerts) throws Exception {
169170
// SSLContext which contains both the key and the trust material and will be used
170171
// by the server
171-
final SSLContext serverSSLCtx = new SimpleSSLContext().get();
172-
assertNotNull(serverSSLCtx, "could not create SSLContext");
173172
final HttpsConfigurator configurator = new HttpsConfigurator(serverSSLCtx) {
174173
@Override
175174
public void configure(final HttpsParameters params) {
@@ -276,8 +275,6 @@ public void configure(final HttpsParameters params) {
276275
public void testServerWantClientAuth(final boolean presentClientCerts) throws Exception {
277276
// SSLContext which contains both the key and the trust material and will be used
278277
// by the server
279-
final SSLContext serverSSLCtx = new SimpleSSLContext().get();
280-
assertNotNull(serverSSLCtx, "could not create SSLContext");
281278
final HttpsConfigurator configurator = new HttpsConfigurator(serverSSLCtx) {
282279
@Override
283280
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
@@ -73,7 +73,7 @@
7373
*/
7474
public class SANTest implements HttpServerAdapters {
7575

76-
static SSLContext ctx;
76+
private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
7777

7878
static HttpServer getHttpsServer(InetSocketAddress addr, Executor exec, SSLContext ctx) throws Exception {
7979
HttpsServer server = HttpsServer.create(addr, 0);
@@ -122,7 +122,6 @@ public static void main (String[] args) throws Exception {
122122
ExecutorService executor=null;
123123
try {
124124
System.out.print ("SANTest: ");
125-
ctx = new SimpleSSLContext().get();
126125
executor = Executors.newCachedThreadPool();
127126

128127
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
@@ -55,7 +55,7 @@ public static void main (String[] args) throws Exception {
5555
HttpsServer server = HttpsServer.create (addr, 0);
5656
HttpContext ctx = server.createContext ("/test", handler);
5757
ExecutorService executor = Executors.newCachedThreadPool();
58-
SSLContext ssl = new SimpleSSLContext().get();
58+
SSLContext ssl = SimpleSSLContext.findSSLContext();
5959
server.setExecutor (executor);
6060
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
6161
server.start ();

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

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