Skip to content

Commit e797879

Browse files
committed
specify nullability in package org.openqa.selenium.remote
* Mark everything as non-nullable by default, and * Mark only the needed methods/parameters as nullable. Partially implements #14291
1 parent b6a1ff4 commit e797879

File tree

139 files changed

+968
-431
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+968
-431
lines changed

java/src/org/openqa/selenium/Platform.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ public static Platform getCurrent() {
416416
* @param osName the operating system name to determine the platform of
417417
* @return the most likely platform based on given operating system name
418418
*/
419-
public static Platform extractFromSysProperty(String osName) {
419+
public static Platform extractFromSysProperty(@Nullable String osName) {
420420
return extractFromSysProperty(osName, System.getProperty("os.version", ""));
421421
}
422422

@@ -429,7 +429,8 @@ public static Platform extractFromSysProperty(String osName) {
429429
* @param osVersion the operating system version to determine the platform of
430430
* @return the most likely platform based on given operating system name and version
431431
*/
432-
public static Platform extractFromSysProperty(String osName, String osVersion) {
432+
public static Platform extractFromSysProperty(
433+
@Nullable String osName, @Nullable String osVersion) {
433434
osName = requireNonNullElse(osName, "");
434435
osVersion = requireNonNullElse(osVersion, "");
435436
osName = osName.toLowerCase(Locale.ENGLISH);
@@ -516,6 +517,7 @@ public String[] getPartOfOsName() {
516517
* @return true if platforms are approximately similar, false otherwise
517518
*/
518519
public boolean is(Platform compareWith) {
520+
Platform family = this.family();
519521
return
520522
// Any platform is itself
521523
this == compareWith
@@ -524,7 +526,7 @@ public boolean is(Platform compareWith) {
524526
compareWith == ANY
525527
||
526528
// And any Platform which is not a platform type belongs to the same family
527-
(this.family() != null && this.family().is(compareWith));
529+
(family != null && family.is(compareWith));
528530
}
529531

530532
/**

java/src/org/openqa/selenium/chrome/ChromeDriverService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public class ChromeDriverService extends DriverService {
104104
public ChromeDriverService(
105105
@Nullable File executable,
106106
int port,
107-
@Nullable Duration timeout,
107+
Duration timeout,
108108
@Nullable List<String> args,
109109
@Nullable Map<String, String> environment)
110110
throws IOException {
@@ -328,7 +328,7 @@ protected List<String> createArgs() {
328328
protected ChromeDriverService createDriverService(
329329
@Nullable File exe,
330330
int port,
331-
@Nullable Duration timeout,
331+
Duration timeout,
332332
@Nullable List<String> args,
333333
@Nullable Map<String, String> environment) {
334334
try {

java/src/org/openqa/selenium/devtools/Connection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.function.Consumer;
4848
import java.util.logging.Level;
4949
import java.util.logging.Logger;
50+
import org.jspecify.annotations.NullMarked;
5051
import org.jspecify.annotations.Nullable;
5152
import org.openqa.selenium.WebDriverException;
5253
import org.openqa.selenium.devtools.idealized.target.model.SessionID;
@@ -242,6 +243,7 @@ public void close() {
242243
this.isClosed.set(true);
243244
}
244245

246+
@NullMarked
245247
private class Listener implements WebSocket.Listener {
246248

247249
@Override

java/src/org/openqa/selenium/edge/EdgeDriverService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public class EdgeDriverService extends DriverService {
100100
public EdgeDriverService(
101101
@Nullable File executable,
102102
int port,
103-
@Nullable Duration timeout,
103+
Duration timeout,
104104
@Nullable List<String> args,
105105
@Nullable Map<String, String> environment)
106106
throws IOException {
@@ -335,7 +335,7 @@ protected List<String> createArgs() {
335335
protected EdgeDriverService createDriverService(
336336
@Nullable File exe,
337337
int port,
338-
@Nullable Duration timeout,
338+
Duration timeout,
339339
@Nullable List<String> args,
340340
@Nullable Map<String, String> environment) {
341341
try {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public abstract class FirefoxDriverService extends DriverService {
3838
protected FirefoxDriverService(
3939
@Nullable File executable,
4040
int port,
41-
@Nullable Duration timeout,
41+
Duration timeout,
4242
@Nullable List<String> args,
4343
@Nullable Map<String, String> environment)
4444
throws IOException {

java/src/org/openqa/selenium/grid/web/ReverseProxyHandler.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
6767
toUpstream.setAttribute(attributeName, req.getAttribute(attributeName));
6868
}
6969

70-
for (String name : req.getQueryParameterNames()) {
71-
for (String value : req.getQueryParameters(name)) {
72-
toUpstream.addQueryParameter(name, value);
73-
}
74-
}
70+
req.forEachQueryParameter(
71+
(name, value) -> {
72+
toUpstream.addQueryParameter(name, value);
73+
});
7574

7675
req.forEachHeader(
7776
(name, value) -> {

java/src/org/openqa/selenium/ie/InternetExplorerDriverService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class InternetExplorerDriverService extends DriverService {
7979
public InternetExplorerDriverService(
8080
@Nullable File executable,
8181
int port,
82-
@Nullable Duration timeout,
82+
Duration timeout,
8383
@Nullable List<String> args,
8484
@Nullable Map<String, String> environment)
8585
throws IOException {
@@ -240,7 +240,7 @@ protected List<String> createArgs() {
240240
protected InternetExplorerDriverService createDriverService(
241241
@Nullable File exe,
242242
int port,
243-
@Nullable Duration timeout,
243+
Duration timeout,
244244
@Nullable List<String> args,
245245
@Nullable Map<String, String> environment) {
246246
try {

java/src/org/openqa/selenium/json/Json.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.lang.reflect.Type;
2727
import java.util.List;
2828
import java.util.Map;
29+
import org.jspecify.annotations.Nullable;
2930
import org.openqa.selenium.internal.Require;
3031

3132
/**
@@ -116,7 +117,7 @@ public class Json {
116117
* @param toConvert the object to be serialized
117118
* @return JSON string representing the specified object
118119
*/
119-
public String toJson(Object toConvert) {
120+
public String toJson(@Nullable Object toConvert) {
120121
return toJson(toConvert, JsonOutput.MAX_DEPTH);
121122
}
122123

@@ -128,7 +129,7 @@ public String toJson(Object toConvert) {
128129
* @return JSON string representing the specified object
129130
* @throws JsonException if an I/O exception is encountered
130131
*/
131-
public String toJson(Object toConvert, int maxDepth) {
132+
public String toJson(@Nullable Object toConvert, int maxDepth) {
132133
try (Writer writer = new StringWriter();
133134
JsonOutput jsonOutput = newOutput(writer)) {
134135
jsonOutput.write(toConvert, maxDepth);

java/src/org/openqa/selenium/remote/AbstractDriverOptions.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.openqa.selenium.remote;
1919

20+
import static java.util.Collections.unmodifiableMap;
21+
import static java.util.Objects.requireNonNull;
2022
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS;
2123
import static org.openqa.selenium.remote.CapabilityType.BROWSER_VERSION;
2224
import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS;
@@ -34,7 +36,6 @@
3436
import java.util.Set;
3537
import java.util.TreeMap;
3638
import java.util.TreeSet;
37-
import org.jspecify.annotations.NonNull;
3839
import org.jspecify.annotations.Nullable;
3940
import org.openqa.selenium.MutableCapabilities;
4041
import org.openqa.selenium.PageLoadStrategy;
@@ -58,23 +59,23 @@ public DO setImplicitWaitTimeout(Duration timeout) {
5859
Map<String, Number> timeouts = getTimeouts();
5960
timeouts.put("implicit", timeout.toMillis());
6061

61-
setCapability(TIMEOUTS, Collections.unmodifiableMap(timeouts));
62+
setCapability(TIMEOUTS, unmodifiableMap(timeouts));
6263
return self();
6364
}
6465

6566
public DO setPageLoadTimeout(Duration timeout) {
6667
Map<String, Number> timeouts = getTimeouts();
6768
timeouts.put("pageLoad", timeout.toMillis());
6869

69-
setCapability(TIMEOUTS, Collections.unmodifiableMap(timeouts));
70+
setCapability(TIMEOUTS, unmodifiableMap(timeouts));
7071
return self();
7172
}
7273

7374
public DO setScriptTimeout(Duration timeout) {
7475
Map<String, Number> timeouts = getTimeouts();
7576
timeouts.put("script", timeout.toMillis());
7677

77-
setCapability(TIMEOUTS, Collections.unmodifiableMap(timeouts));
78+
setCapability(TIMEOUTS, unmodifiableMap(timeouts));
7879
return self();
7980
}
8081

@@ -109,7 +110,6 @@ public DO setEnableDownloads(boolean enableDownloads) {
109110
return self();
110111
}
111112

112-
@NonNull
113113
@SuppressWarnings("unchecked")
114114
private DO self() {
115115
return (DO) this;
@@ -125,7 +125,7 @@ public Set<String> getCapabilityNames() {
125125
protected abstract Set<String> getExtraCapabilityNames();
126126

127127
@Override
128-
public Object getCapability(String capabilityName) {
128+
public @Nullable Object getCapability(String capabilityName) {
129129
Require.nonNull("Capability name", capabilityName);
130130

131131
if (getExtraCapabilityNames().contains(capabilityName)) {
@@ -140,8 +140,9 @@ public Object getCapability(String capabilityName) {
140140
@Override
141141
public Map<String, Object> asMap() {
142142
Map<String, Object> toReturn = new TreeMap<>(super.asMap());
143-
getExtraCapabilityNames().forEach(name -> toReturn.put(name, getCapability(name)));
144-
return Collections.unmodifiableMap(toReturn);
143+
getExtraCapabilityNames()
144+
.forEach(name -> toReturn.put(name, requireNonNull(getCapability(name))));
145+
return unmodifiableMap(toReturn);
145146
}
146147

147148
private Map<String, Number> getTimeouts() {

java/src/org/openqa/selenium/remote/AddHasAuthentication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static org.openqa.selenium.remote.Browser.OPERA;
2323

2424
import java.util.function.Predicate;
25-
import java.util.logging.Logger;
2625
import org.openqa.selenium.Capabilities;
2726
import org.openqa.selenium.HasAuthentication;
2827
import org.openqa.selenium.WebDriver;
@@ -32,7 +31,6 @@
3231

3332
public class AddHasAuthentication implements AugmenterProvider<HasAuthentication> {
3433

35-
private static final Logger LOG = Logger.getLogger(AddHasAuthentication.class.getName());
3634
private static final Predicate<String> IS_CHROMIUM_BROWSER =
3735
name -> CHROME.is(name) || EDGE.is(name) || OPERA.is(name);
3836

0 commit comments

Comments
 (0)