diff --git a/java/src/org/openqa/selenium/ie/BUILD.bazel b/java/src/org/openqa/selenium/ie/BUILD.bazel index b6f6e93c3619f..6fcef4dea869a 100644 --- a/java/src/org/openqa/selenium/ie/BUILD.bazel +++ b/java/src/org/openqa/selenium/ie/BUILD.bazel @@ -15,5 +15,6 @@ java_export( "//java/src/org/openqa/selenium:core", "//java/src/org/openqa/selenium/manager", "//java/src/org/openqa/selenium/remote", + "@maven//:org_jspecify_jspecify", ], ) diff --git a/java/src/org/openqa/selenium/ie/InternetExplorerDriver.java b/java/src/org/openqa/selenium/ie/InternetExplorerDriver.java index 7da71cf514cd6..b1496f48a0491 100644 --- a/java/src/org/openqa/selenium/ie/InternetExplorerDriver.java +++ b/java/src/org/openqa/selenium/ie/InternetExplorerDriver.java @@ -17,6 +17,7 @@ package org.openqa.selenium.ie; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.Beta; import org.openqa.selenium.Capabilities; import org.openqa.selenium.Platform; @@ -108,20 +109,13 @@ public InternetExplorerDriver( * @param options The options required from InternetExplorerDriver. */ public InternetExplorerDriver( - InternetExplorerDriverService service, - InternetExplorerOptions options, - ClientConfig clientConfig) { - if (options == null) { - options = new InternetExplorerOptions(); - } - if (service == null) { - service = InternetExplorerDriverService.createDefaultService(); - } + @Nullable InternetExplorerDriverService service, + @Nullable InternetExplorerOptions options, + @Nullable ClientConfig clientConfig) { + options = options == null ? new InternetExplorerOptions() : options; + service = service == null ? InternetExplorerDriverService.createDefaultService() : service; + clientConfig = clientConfig == null ? ClientConfig.defaultConfig() : clientConfig; service.setExecutable(new DriverFinder(service, options).getDriverPath()); - if (clientConfig == null) { - clientConfig = ClientConfig.defaultConfig(); - } - run(service, options, clientConfig); } diff --git a/java/src/org/openqa/selenium/remote/BUILD.bazel b/java/src/org/openqa/selenium/remote/BUILD.bazel index d5eabf080dcea..e1bac58daa94f 100644 --- a/java/src/org/openqa/selenium/remote/BUILD.bazel +++ b/java/src/org/openqa/selenium/remote/BUILD.bazel @@ -78,6 +78,7 @@ java_library( "//java/src/org/openqa/selenium/support/decorators", artifact("com.google.guava:guava"), artifact("net.bytebuddy:byte-buddy"), + artifact("org.jspecify:jspecify"), ], ) diff --git a/java/src/org/openqa/selenium/remote/DesiredCapabilities.java b/java/src/org/openqa/selenium/remote/DesiredCapabilities.java index 1b2d2de95686b..501eef6965fb3 100644 --- a/java/src/org/openqa/selenium/remote/DesiredCapabilities.java +++ b/java/src/org/openqa/selenium/remote/DesiredCapabilities.java @@ -23,6 +23,8 @@ import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME; import java.util.Map; +import java.util.Optional; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.Capabilities; import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.Platform; @@ -39,12 +41,8 @@ public DesiredCapabilities() { // no-arg constructor } - public DesiredCapabilities(Map rawMap) { - if (rawMap == null) { - return; - } - - rawMap.forEach(this::setCapability); + public DesiredCapabilities(@Nullable Map rawMap) { + Optional.ofNullable(rawMap).ifPresent(map -> map.forEach(this::setCapability)); } public DesiredCapabilities(Capabilities other) { @@ -94,10 +92,9 @@ public void setAcceptInsecureCerts(boolean acceptInsecureCerts) { * @return DesiredCapabilities after the merge */ @Override - public DesiredCapabilities merge(Capabilities extraCapabilities) { - if (extraCapabilities != null) { - extraCapabilities.asMap().forEach(this::setCapability); - } + public DesiredCapabilities merge(@Nullable Capabilities extraCapabilities) { + Optional.ofNullable(extraCapabilities) + .ifPresent(caps -> caps.asMap().forEach(this::setCapability)); return this; } } diff --git a/java/src/org/openqa/selenium/remote/service/DriverService.java b/java/src/org/openqa/selenium/remote/service/DriverService.java index d957b694fb004..cc16bcb96acca 100644 --- a/java/src/org/openqa/selenium/remote/service/DriverService.java +++ b/java/src/org/openqa/selenium/remote/service/DriverService.java @@ -41,6 +41,7 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Logger; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.Beta; import org.openqa.selenium.Capabilities; import org.openqa.selenium.ImmutableCapabilities; @@ -145,15 +146,15 @@ protected Capabilities getDefaultDriverOptions() { return new ImmutableCapabilities(); } - protected String getDriverName() { + protected @Nullable String getDriverName() { return null; } - public String getDriverProperty() { + public @Nullable String getDriverProperty() { return null; } - protected File getDriverExecutable() { + protected @Nullable File getDriverExecutable() { return null; }