Skip to content

Commit 16971b4

Browse files
iampopovichdiemol
andauthored
[java] Add @nullable annotations to Firefox and Gecko driver service (#15999)
Add @nullable annotations to Firefox and Gecko driver service constructors and parameters Co-authored-by: Diego Molina <[email protected]>
1 parent 1c1db92 commit 16971b4

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

java/src/org/openqa/selenium/firefox/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ java_export(
1616
"//java/src/org/openqa/selenium/json",
1717
"//java/src/org/openqa/selenium/manager",
1818
"//java/src/org/openqa/selenium/remote",
19+
"@maven//:org_jspecify_jspecify",
1920
],
2021
)

java/src/org/openqa/selenium/firefox/FirefoxDriverService.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.time.Duration;
2323
import java.util.List;
2424
import java.util.Map;
25+
import org.jspecify.annotations.Nullable;
2526
import org.openqa.selenium.remote.service.DriverService;
2627

2728
public abstract class FirefoxDriverService extends DriverService {
@@ -35,11 +36,11 @@ public abstract class FirefoxDriverService extends DriverService {
3536
* @throws IOException If an I/O error occurs.
3637
*/
3738
public FirefoxDriverService(
38-
File executable,
39+
@Nullable File executable,
3940
int port,
40-
Duration timeout,
41-
List<String> args,
42-
Map<String, String> environment)
41+
@Nullable Duration timeout,
42+
@Nullable List<String> args,
43+
@Nullable Map<String, String> environment)
4344
throws IOException {
4445
super(executable, port, timeout, args, environment);
4546
}

java/src/org/openqa/selenium/firefox/GeckoDriverService.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.List;
3333
import java.util.Locale;
3434
import java.util.Map;
35+
import org.jspecify.annotations.Nullable;
3536
import org.openqa.selenium.Capabilities;
3637
import org.openqa.selenium.WebDriverException;
3738
import org.openqa.selenium.net.PortProber;
@@ -83,11 +84,11 @@ public class GeckoDriverService extends FirefoxDriverService {
8384
* @throws IOException If an I/O error occurs.
8485
*/
8586
public GeckoDriverService(
86-
File executable,
87+
@Nullable File executable,
8788
int port,
88-
Duration timeout,
89-
List<String> args,
90-
Map<String, String> environment)
89+
@Nullable Duration timeout,
90+
@Nullable List<String> args,
91+
@Nullable Map<String, String> environment)
9192
throws IOException {
9293
super(
9394
executable,
@@ -142,10 +143,10 @@ protected boolean hasShutdownEndpoint() {
142143
public static class Builder
143144
extends FirefoxDriverService.Builder<GeckoDriverService, GeckoDriverService.Builder> {
144145

145-
private String allowHosts;
146-
private FirefoxDriverLogLevel logLevel;
147-
private Boolean logTruncate;
148-
private File profileRoot;
146+
private @Nullable String allowHosts;
147+
private @Nullable FirefoxDriverLogLevel logLevel;
148+
private @Nullable Boolean logTruncate;
149+
private @Nullable File profileRoot;
149150

150151
@Override
151152
public int score(Capabilities capabilities) {
@@ -168,7 +169,7 @@ public int score(Capabilities capabilities) {
168169
* @param allowHosts Space-separated list of host names.
169170
* @return A self reference.
170171
*/
171-
public Builder withAllowHosts(String allowHosts) {
172+
public Builder withAllowHosts(@Nullable String allowHosts) {
172173
this.allowHosts = allowHosts;
173174
return this;
174175
}
@@ -177,7 +178,7 @@ public Builder withAllowHosts(String allowHosts) {
177178
* @param logLevel which log events to record.
178179
* @return A self reference.
179180
*/
180-
public Builder withLogLevel(FirefoxDriverLogLevel logLevel) {
181+
public Builder withLogLevel(@Nullable FirefoxDriverLogLevel logLevel) {
181182
this.logLevel = logLevel;
182183
return this;
183184
}
@@ -187,7 +188,7 @@ public Builder withLogLevel(FirefoxDriverLogLevel logLevel) {
187188
* default; setting "false" removes truncation
188189
* @return A self reference.
189190
*/
190-
public Builder withTruncatedLogs(Boolean truncate) {
191+
public Builder withTruncatedLogs(@Nullable Boolean truncate) {
191192
this.logTruncate = truncate;
192193
return this;
193194
}
@@ -198,7 +199,7 @@ public Builder withTruncatedLogs(Boolean truncate) {
198199
* @param root location to store temporary profiles Defaults to the system temporary directory.
199200
* @return A self reference.
200201
*/
201-
public GeckoDriverService.Builder withProfileRoot(File root) {
202+
public GeckoDriverService.Builder withProfileRoot(@Nullable File root) {
202203
this.profileRoot = root;
203204
return this;
204205
}
@@ -257,7 +258,11 @@ protected List<String> createArgs() {
257258

258259
@Override
259260
protected GeckoDriverService createDriverService(
260-
File exe, int port, Duration timeout, List<String> args, Map<String, String> environment) {
261+
@Nullable File exe,
262+
int port,
263+
@Nullable Duration timeout,
264+
@Nullable List<String> args,
265+
@Nullable Map<String, String> environment) {
261266
try {
262267
return new GeckoDriverService(exe, port, timeout, args, environment);
263268
} catch (IOException e) {

0 commit comments

Comments
 (0)