Skip to content

Commit 8460e4e

Browse files
authored
Lazy initialisation of the singleton default client factory instance (#9261)
1 parent d8c0d8e commit 8460e4e

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

java/client/src/org/openqa/selenium/remote/HttpCommandExecutor.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545

4646
public class HttpCommandExecutor implements CommandExecutor, NeedsLocalLogs {
4747

48-
private static final HttpClient.Factory defaultClientFactory = HttpClient.Factory.createDefault();
49-
5048
private final URL remoteServer;
5149
private final HttpClient client;
5250
private final HttpClient.Factory httpClientFactory;
@@ -56,14 +54,22 @@ public class HttpCommandExecutor implements CommandExecutor, NeedsLocalLogs {
5654

5755
private LocalLogs logs = LocalLogs.getNullLogger();
5856

57+
private static class DefaultClientFactoryHolder {
58+
static HttpClient.Factory defaultClientFactory = HttpClient.Factory.createDefault();
59+
}
60+
61+
public static HttpClient.Factory getDefaultClientFactory() {
62+
return DefaultClientFactoryHolder.defaultClientFactory;
63+
}
64+
5965
public HttpCommandExecutor(URL addressOfRemoteServer) {
6066
this(emptyMap(), Require.nonNull("Server URL", addressOfRemoteServer));
6167
}
6268

6369
public HttpCommandExecutor(ClientConfig config) {
6470
this(emptyMap(),
65-
Require.nonNull("HTTP client configuration", config),
66-
defaultClientFactory);
71+
Require.nonNull("HTTP client configuration", config),
72+
getDefaultClientFactory());
6773
}
6874

6975
/**
@@ -78,8 +84,8 @@ public HttpCommandExecutor(
7884
URL addressOfRemoteServer)
7985
{
8086
this(Require.nonNull("Additional commands", additionalCommands),
81-
Require.nonNull("Server URL", addressOfRemoteServer),
82-
defaultClientFactory);
87+
Require.nonNull("Server URL", addressOfRemoteServer),
88+
getDefaultClientFactory());
8389
}
8490

8591
public HttpCommandExecutor(

0 commit comments

Comments
 (0)