From 4d742a53691819e4c5048ffd9b9bf76b6a10071f Mon Sep 17 00:00:00 2001 From: Alex Popov Date: Sun, 6 Jul 2025 04:56:19 +0700 Subject: [PATCH] Add @Nullable annotations to Firefox and Gecko driver service constructors and parameters --- .../org/openqa/selenium/firefox/BUILD.bazel | 1 + .../firefox/FirefoxDriverService.java | 9 +++--- .../selenium/firefox/GeckoDriverService.java | 31 +++++++++++-------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/java/src/org/openqa/selenium/firefox/BUILD.bazel b/java/src/org/openqa/selenium/firefox/BUILD.bazel index e4c1f17455d61..24106ab3859d9 100644 --- a/java/src/org/openqa/selenium/firefox/BUILD.bazel +++ b/java/src/org/openqa/selenium/firefox/BUILD.bazel @@ -16,5 +16,6 @@ java_export( "//java/src/org/openqa/selenium/json", "//java/src/org/openqa/selenium/manager", "//java/src/org/openqa/selenium/remote", + "@maven//:org_jspecify_jspecify", ], ) diff --git a/java/src/org/openqa/selenium/firefox/FirefoxDriverService.java b/java/src/org/openqa/selenium/firefox/FirefoxDriverService.java index d26ea6db406a7..65e9ed83be01d 100644 --- a/java/src/org/openqa/selenium/firefox/FirefoxDriverService.java +++ b/java/src/org/openqa/selenium/firefox/FirefoxDriverService.java @@ -22,6 +22,7 @@ import java.time.Duration; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.remote.service.DriverService; public abstract class FirefoxDriverService extends DriverService { @@ -35,11 +36,11 @@ public abstract class FirefoxDriverService extends DriverService { * @throws IOException If an I/O error occurs. */ public FirefoxDriverService( - File executable, + @Nullable File executable, int port, - Duration timeout, - List args, - Map environment) + @Nullable Duration timeout, + @Nullable List args, + @Nullable Map environment) throws IOException { super(executable, port, timeout, args, environment); } diff --git a/java/src/org/openqa/selenium/firefox/GeckoDriverService.java b/java/src/org/openqa/selenium/firefox/GeckoDriverService.java index c2085408b8162..656351917aab1 100644 --- a/java/src/org/openqa/selenium/firefox/GeckoDriverService.java +++ b/java/src/org/openqa/selenium/firefox/GeckoDriverService.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.net.PortProber; @@ -83,11 +84,11 @@ public class GeckoDriverService extends FirefoxDriverService { * @throws IOException If an I/O error occurs. */ public GeckoDriverService( - File executable, + @Nullable File executable, int port, - Duration timeout, - List args, - Map environment) + @Nullable Duration timeout, + @Nullable List args, + @Nullable Map environment) throws IOException { super( executable, @@ -142,10 +143,10 @@ protected boolean hasShutdownEndpoint() { public static class Builder extends FirefoxDriverService.Builder { - private String allowHosts; - private FirefoxDriverLogLevel logLevel; - private Boolean logTruncate; - private File profileRoot; + private @Nullable String allowHosts; + private @Nullable FirefoxDriverLogLevel logLevel; + private @Nullable Boolean logTruncate; + private @Nullable File profileRoot; @Override public int score(Capabilities capabilities) { @@ -168,7 +169,7 @@ public int score(Capabilities capabilities) { * @param allowHosts Space-separated list of host names. * @return A self reference. */ - public Builder withAllowHosts(String allowHosts) { + public Builder withAllowHosts(@Nullable String allowHosts) { this.allowHosts = allowHosts; return this; } @@ -177,7 +178,7 @@ public Builder withAllowHosts(String allowHosts) { * @param logLevel which log events to record. * @return A self reference. */ - public Builder withLogLevel(FirefoxDriverLogLevel logLevel) { + public Builder withLogLevel(@Nullable FirefoxDriverLogLevel logLevel) { this.logLevel = logLevel; return this; } @@ -187,7 +188,7 @@ public Builder withLogLevel(FirefoxDriverLogLevel logLevel) { * default; setting "false" removes truncation * @return A self reference. */ - public Builder withTruncatedLogs(Boolean truncate) { + public Builder withTruncatedLogs(@Nullable Boolean truncate) { this.logTruncate = truncate; return this; } @@ -198,7 +199,7 @@ public Builder withTruncatedLogs(Boolean truncate) { * @param root location to store temporary profiles Defaults to the system temporary directory. * @return A self reference. */ - public GeckoDriverService.Builder withProfileRoot(File root) { + public GeckoDriverService.Builder withProfileRoot(@Nullable File root) { this.profileRoot = root; return this; } @@ -257,7 +258,11 @@ protected List createArgs() { @Override protected GeckoDriverService createDriverService( - File exe, int port, Duration timeout, List args, Map environment) { + @Nullable File exe, + int port, + @Nullable Duration timeout, + @Nullable List args, + @Nullable Map environment) { try { return new GeckoDriverService(exe, port, timeout, args, environment); } catch (IOException e) {