Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions java/src/org/openqa/selenium/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public static Platform getCurrent() {
* @param osName the operating system name to determine the platform of
* @return the most likely platform based on given operating system name
*/
public static Platform extractFromSysProperty(String osName) {
public static Platform extractFromSysProperty(@Nullable String osName) {
return extractFromSysProperty(osName, System.getProperty("os.version", ""));
}

Expand All @@ -429,7 +429,8 @@ public static Platform extractFromSysProperty(String osName) {
* @param osVersion the operating system version to determine the platform of
* @return the most likely platform based on given operating system name and version
*/
public static Platform extractFromSysProperty(String osName, String osVersion) {
public static Platform extractFromSysProperty(
@Nullable String osName, @Nullable String osVersion) {
osName = requireNonNullElse(osName, "");
osVersion = requireNonNullElse(osVersion, "");
osName = osName.toLowerCase(Locale.ENGLISH);
Expand Down Expand Up @@ -516,6 +517,7 @@ public String[] getPartOfOsName() {
* @return true if platforms are approximately similar, false otherwise
*/
public boolean is(Platform compareWith) {
Platform family = this.family();
return
// Any platform is itself
this == compareWith
Expand All @@ -524,7 +526,7 @@ public boolean is(Platform compareWith) {
compareWith == ANY
||
// And any Platform which is not a platform type belongs to the same family
(this.family() != null && this.family().is(compareWith));
(family != null && family.is(compareWith));
}

/**
Expand Down
17 changes: 15 additions & 2 deletions java/src/org/openqa/selenium/bidi/BiDi.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.logging.Logger;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.internal.Require;

public class BiDi implements Closeable {
private static final Logger LOG = Logger.getLogger(BiDi.class.getName());

private final Duration timeout;
private final Connection connection;
Expand All @@ -47,9 +50,19 @@ public BiDi(Connection connection, Duration timeout) {

@Override
public void close() {
clearListeners();
try {
clearListeners();
} catch (WebDriverException e) {
LOG.warning(() -> "Failed to clear BiDi listeners: " + e);
}

disconnectSession();
connection.close();

try {
connection.close();
} catch (WebDriverException e) {
LOG.warning(() -> "Failed to close BiDi connection: " + e);
}
}

public void disconnectSession() {
Expand Down
4 changes: 2 additions & 2 deletions java/src/org/openqa/selenium/chrome/ChromeDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class ChromeDriverService extends DriverService {
public ChromeDriverService(
@Nullable File executable,
int port,
@Nullable Duration timeout,
Duration timeout,
@Nullable List<String> args,
@Nullable Map<String, String> environment)
throws IOException {
Expand Down Expand Up @@ -328,7 +328,7 @@ protected List<String> createArgs() {
protected ChromeDriverService createDriverService(
@Nullable File exe,
int port,
@Nullable Duration timeout,
Duration timeout,
@Nullable List<String> args,
@Nullable Map<String, String> environment) {
try {
Expand Down
2 changes: 2 additions & 0 deletions java/src/org/openqa/selenium/devtools/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.devtools.idealized.target.model.SessionID;
Expand Down Expand Up @@ -242,6 +243,7 @@ public void close() {
this.isClosed.set(true);
}

@NullMarked
private class Listener implements WebSocket.Listener {

@Override
Expand Down
4 changes: 2 additions & 2 deletions java/src/org/openqa/selenium/edge/EdgeDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class EdgeDriverService extends DriverService {
public EdgeDriverService(
@Nullable File executable,
int port,
@Nullable Duration timeout,
Duration timeout,
@Nullable List<String> args,
@Nullable Map<String, String> environment)
throws IOException {
Expand Down Expand Up @@ -335,7 +335,7 @@ protected List<String> createArgs() {
protected EdgeDriverService createDriverService(
@Nullable File exe,
int port,
@Nullable Duration timeout,
Duration timeout,
@Nullable List<String> args,
@Nullable Map<String, String> environment) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class FirefoxDriverService extends DriverService {
protected FirefoxDriverService(
@Nullable File executable,
int port,
@Nullable Duration timeout,
Duration timeout,
@Nullable List<String> args,
@Nullable Map<String, String> environment)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
toUpstream.setAttribute(attributeName, req.getAttribute(attributeName));
}

for (String name : req.getQueryParameterNames()) {
for (String value : req.getQueryParameters(name)) {
toUpstream.addQueryParameter(name, value);
}
}
req.forEachQueryParameter(
(name, value) -> {
toUpstream.addQueryParameter(name, value);
});

req.forEachHeader(
(name, value) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class InternetExplorerDriverService extends DriverService {
public InternetExplorerDriverService(
@Nullable File executable,
int port,
@Nullable Duration timeout,
Duration timeout,
@Nullable List<String> args,
@Nullable Map<String, String> environment)
throws IOException {
Expand Down Expand Up @@ -240,7 +240,7 @@ protected List<String> createArgs() {
protected InternetExplorerDriverService createDriverService(
@Nullable File exe,
int port,
@Nullable Duration timeout,
Duration timeout,
@Nullable List<String> args,
@Nullable Map<String, String> environment) {
try {
Expand Down
5 changes: 3 additions & 2 deletions java/src/org/openqa/selenium/json/Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.internal.Require;

/**
Expand Down Expand Up @@ -116,7 +117,7 @@ public class Json {
* @param toConvert the object to be serialized
* @return JSON string representing the specified object
*/
public String toJson(Object toConvert) {
public String toJson(@Nullable Object toConvert) {
return toJson(toConvert, JsonOutput.MAX_DEPTH);
}

Expand All @@ -128,7 +129,7 @@ public String toJson(Object toConvert) {
* @return JSON string representing the specified object
* @throws JsonException if an I/O exception is encountered
*/
public String toJson(Object toConvert, int maxDepth) {
public String toJson(@Nullable Object toConvert, int maxDepth) {
try (Writer writer = new StringWriter();
JsonOutput jsonOutput = newOutput(writer)) {
jsonOutput.write(toConvert, maxDepth);
Expand Down
17 changes: 9 additions & 8 deletions java/src/org/openqa/selenium/remote/AbstractDriverOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.openqa.selenium.remote;

import static java.util.Collections.unmodifiableMap;
import static java.util.Objects.requireNonNull;
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS;
import static org.openqa.selenium.remote.CapabilityType.BROWSER_VERSION;
import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS;
Expand All @@ -34,7 +36,6 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.PageLoadStrategy;
Expand All @@ -58,23 +59,23 @@ public DO setImplicitWaitTimeout(Duration timeout) {
Map<String, Number> timeouts = getTimeouts();
timeouts.put("implicit", timeout.toMillis());

setCapability(TIMEOUTS, Collections.unmodifiableMap(timeouts));
setCapability(TIMEOUTS, unmodifiableMap(timeouts));
return self();
}

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

setCapability(TIMEOUTS, Collections.unmodifiableMap(timeouts));
setCapability(TIMEOUTS, unmodifiableMap(timeouts));
return self();
}

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

setCapability(TIMEOUTS, Collections.unmodifiableMap(timeouts));
setCapability(TIMEOUTS, unmodifiableMap(timeouts));
return self();
}

Expand Down Expand Up @@ -109,7 +110,6 @@ public DO setEnableDownloads(boolean enableDownloads) {
return self();
}

@NonNull
@SuppressWarnings("unchecked")
private DO self() {
return (DO) this;
Expand All @@ -125,7 +125,7 @@ public Set<String> getCapabilityNames() {
protected abstract Set<String> getExtraCapabilityNames();

@Override
public Object getCapability(String capabilityName) {
public @Nullable Object getCapability(String capabilityName) {
Require.nonNull("Capability name", capabilityName);

if (getExtraCapabilityNames().contains(capabilityName)) {
Expand All @@ -140,8 +140,9 @@ public Object getCapability(String capabilityName) {
@Override
public Map<String, Object> asMap() {
Map<String, Object> toReturn = new TreeMap<>(super.asMap());
getExtraCapabilityNames().forEach(name -> toReturn.put(name, getCapability(name)));
return Collections.unmodifiableMap(toReturn);
getExtraCapabilityNames()
.forEach(name -> toReturn.put(name, requireNonNull(getCapability(name))));
return unmodifiableMap(toReturn);
}

private Map<String, Number> getTimeouts() {
Expand Down
2 changes: 0 additions & 2 deletions java/src/org/openqa/selenium/remote/AddHasAuthentication.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static org.openqa.selenium.remote.Browser.OPERA;

import java.util.function.Predicate;
import java.util.logging.Logger;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.HasAuthentication;
import org.openqa.selenium.WebDriver;
Expand All @@ -32,7 +31,6 @@

public class AddHasAuthentication implements AugmenterProvider<HasAuthentication> {

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

Expand Down
2 changes: 0 additions & 2 deletions java/src/org/openqa/selenium/remote/AddHasLogEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static org.openqa.selenium.remote.Browser.OPERA;

import java.util.function.Predicate;
import org.jspecify.annotations.NullMarked;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.devtools.HasDevTools;
Expand All @@ -48,7 +47,6 @@ public Class<HasLogEvents> getDescribedInterface() {
public HasLogEvents getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
return new HasLogEvents() {
@Override
@NullMarked
public <X> void onLogEvent(EventType<X> kind) {
if (((RemoteExecuteMethod) executeMethod).getWrappedDriver() instanceof HasDevTools) {
WebDriver driver = ((RemoteExecuteMethod) executeMethod).getWrappedDriver();
Expand Down
9 changes: 6 additions & 3 deletions java/src/org/openqa/selenium/remote/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,28 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.json.JsonInput;

public class Command {

private final SessionId sessionId;
private final @Nullable SessionId sessionId;
private final CommandPayload payload;

public Command(SessionId sessionId, String name) {
this(sessionId, name, new HashMap<>());
}

public Command(SessionId sessionId, String name, Map<String, ?> parameters) {
public Command(@Nullable SessionId sessionId, String name, Map<String, ?> parameters) {
this(sessionId, new CommandPayload(name, parameters));
}

public Command(SessionId sessionId, CommandPayload payload) {
public Command(@Nullable SessionId sessionId, CommandPayload payload) {
this.sessionId = sessionId;
this.payload = payload;
}

@Nullable
public SessionId getSessionId() {
return sessionId;
}
Expand Down Expand Up @@ -105,6 +107,7 @@ private static Command fromJson(JsonInput input) {

input.endObject();

//noinspection DataFlowIssue
return new Command(sessionId, name, parameters);
}
}
2 changes: 0 additions & 2 deletions java/src/org/openqa/selenium/remote/CommandCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.openqa.selenium.remote;

import org.jspecify.annotations.NullMarked;
import org.openqa.selenium.UnsupportedCommandException;
import org.openqa.selenium.remote.http.HttpMethod;

Expand All @@ -26,7 +25,6 @@
*
* @param <T> The type of encoded command.
*/
@NullMarked
public interface CommandCodec<T> {

/**
Expand Down
2 changes: 0 additions & 2 deletions java/src/org/openqa/selenium/remote/CommandInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@

package org.openqa.selenium.remote;

import org.jspecify.annotations.NullMarked;
import org.openqa.selenium.remote.http.HttpMethod;

@NullMarked
public class CommandInfo {
private final String url;
private final HttpMethod method;
Expand Down
7 changes: 3 additions & 4 deletions java/src/org/openqa/selenium/remote/CommandPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@
package org.openqa.selenium.remote;

import java.util.Map;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.internal.Require;

@NullMarked
public class CommandPayload {

private final String name;
private final Map<String, ? extends @Nullable Object> parameters;

public CommandPayload(String name, Map<String, ? extends @Nullable Object> parameters) {
this.name = name;
this.parameters = parameters;
this.name = Require.nonNull("name", name);
this.parameters = Require.nonNull("parameters", parameters);
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public DesiredCapabilities setAcceptInsecureCerts(boolean acceptInsecureCerts) {
* @return DesiredCapabilities after the merge
*/
@Override
public DesiredCapabilities merge(@Nullable Capabilities extraCapabilities) {
public DesiredCapabilities merge(Capabilities extraCapabilities) {
Optional.ofNullable(extraCapabilities)
.ifPresent(caps -> caps.asMap().forEach(this::setCapability));
return this;
Expand Down
Loading
Loading