2020import io .appium .java_client .AppiumClientConfig ;
2121import io .appium .java_client .internal .ReflectionHelpers ;
2222import lombok .Getter ;
23- import org .jspecify .annotations .NonNull ;
23+ import org .jspecify .annotations .NullMarked ;
2424import org .jspecify .annotations .Nullable ;
2525import org .openqa .selenium .SessionNotCreatedException ;
2626import org .openqa .selenium .WebDriverException ;
5353import static java .util .Optional .ofNullable ;
5454import static org .openqa .selenium .remote .DriverCommand .NEW_SESSION ;
5555
56+ @ NullMarked
5657public class AppiumCommandExecutor extends HttpCommandExecutor {
5758
5859 private final Optional <DriverService > serviceOptional ;
5960 @ Getter
60- private final HttpClient . Factory httpClientFactory ;
61+ private final Factory httpClientFactory ;
6162 @ Getter
6263 private final AppiumClientConfig appiumClientConfig ;
6364
@@ -66,32 +67,32 @@ public class AppiumCommandExecutor extends HttpCommandExecutor {
6667 *
6768 * @param additionalCommands is the map of Appium commands
6869 * @param service take a look at {@link DriverService}
69- * @param httpClientFactory take a look at {@link HttpClient. Factory}
70+ * @param httpClientFactory take a look at {@link Factory}
7071 * @param appiumClientConfig take a look at {@link AppiumClientConfig}
7172 */
7273 public AppiumCommandExecutor (
73- @ NonNull Map <String , CommandInfo > additionalCommands ,
74+ Map <String , CommandInfo > additionalCommands ,
7475 @ Nullable DriverService service ,
7576 @ Nullable Factory httpClientFactory ,
76- @ NonNull AppiumClientConfig appiumClientConfig ) {
77+ AppiumClientConfig appiumClientConfig ) {
7778 super (additionalCommands ,
7879 appiumClientConfig ,
79- ofNullable (httpClientFactory ).orElseGet (AppiumCommandExecutor ::getDefaultClientFactory )
80+ ofNullable (httpClientFactory ).orElseGet (HttpCommandExecutor ::getDefaultClientFactory )
8081 );
8182 serviceOptional = ofNullable (service );
8283
83- this .httpClientFactory = httpClientFactory ;
84+ this .httpClientFactory = ofNullable ( httpClientFactory ). orElseGet ( HttpCommandExecutor :: getDefaultClientFactory ) ;
8485 this .appiumClientConfig = appiumClientConfig ;
8586 }
8687
8788 public AppiumCommandExecutor (Map <String , CommandInfo > additionalCommands , DriverService service ,
88- HttpClient . Factory httpClientFactory ) {
89+ @ Nullable Factory httpClientFactory ) {
8990 this (additionalCommands , requireNonNull (service ), httpClientFactory ,
9091 AppiumClientConfig .defaultConfig ().baseUrl (requireNonNull (service ).getUrl ()));
9192 }
9293
9394 public AppiumCommandExecutor (Map <String , CommandInfo > additionalCommands , URL addressOfRemoteServer ,
94- HttpClient . Factory httpClientFactory ) {
95+ @ Nullable Factory httpClientFactory ) {
9596 this (additionalCommands , null , httpClientFactory ,
9697 AppiumClientConfig .defaultConfig ().baseUrl (requireNonNull (addressOfRemoteServer )));
9798 }
@@ -140,6 +141,7 @@ public Map<String, CommandInfo> getAdditionalCommands() {
140141 return getPrivateFieldValue (HttpCommandExecutor .class , "additionalCommands" , Map .class );
141142 }
142143
144+ @ Nullable
143145 protected CommandCodec <HttpRequest > getCommandCodec () {
144146 return this .commandCodec ;
145147 }
@@ -163,12 +165,8 @@ protected HttpClient getClient() {
163165 * @param serverUrl A url to override.
164166 */
165167 protected void overrideServerUrl (URL serverUrl ) {
166- if (this .appiumClientConfig == null ) {
167- return ;
168- }
169168 setPrivateFieldValue (HttpCommandExecutor .class , "client" ,
170- ofNullable (this .httpClientFactory ).orElseGet (AppiumCommandExecutor ::getDefaultClientFactory )
171- .createClient (this .appiumClientConfig .baseUrl (serverUrl )));
169+ this .httpClientFactory .createClient (this .appiumClientConfig .baseUrl (serverUrl )));
172170 }
173171
174172 private Response createSession (Command command ) throws IOException {
@@ -186,7 +184,7 @@ private Response createSession(Command command) throws IOException {
186184 refreshAdditionalCommands ();
187185 setResponseCodec (dialect .getResponseCodec ());
188186 Response response = result .createResponse ();
189- if (this . appiumClientConfig != null && this . appiumClientConfig .isDirectConnectEnabled ()) {
187+ if (appiumClientConfig .isDirectConnectEnabled ()) {
190188 setDirectConnect (response );
191189 }
192190
0 commit comments