Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions java/src/org/openqa/selenium/chromium/AddHasCasting.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.openqa.selenium.chromium;

import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNullElse;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -56,7 +55,7 @@ public HasCasting getImplementation(Capabilities capabilities, ExecuteMethod exe
return new HasCasting() {
@Override
public List<Map<String, String>> getCastSinks() {
return requireNonNullElse(executeMethod.execute(GET_CAST_SINKS, null), emptyList());
return executeMethod.execute(GET_CAST_SINKS, null, emptyList());
}

@Override
Expand Down
14 changes: 12 additions & 2 deletions java/src/org/openqa/selenium/remote/ExecuteMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openqa.selenium.remote;

import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNullElse;

import java.util.Map;
import org.jspecify.annotations.NullMarked;
Expand All @@ -37,9 +38,18 @@ public interface ExecuteMethod {
* @param parameters The parameters to execute that command with
* @return The result of {@link Response#getValue()}.
*/
@Nullable <T> T execute(String commandName, @Nullable Map<String, ?> parameters);
@Nullable Object execute(String commandName, @Nullable Map<String, ?> parameters);

default <T> T execute(String commandName, @Nullable Map<String, ?> parameters, T defaultValue) {
return requireNonNullElse(executeOptional(commandName, parameters), defaultValue);
}

@SuppressWarnings("unchecked")
default @Nullable <T> T executeOptional(String commandName, @Nullable Map<String, ?> parameters) {
return (T) execute(commandName, parameters);
}
Comment thread
qodo-code-review[bot] marked this conversation as resolved.

default <T> T executeRequired(String commandName, @Nullable Map<String, ?> parameters) {
return requireNonNull(execute(commandName, parameters));
return requireNonNull(executeOptional(commandName, parameters));
}
}
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/remote/FedCmDialogImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void selectAccount(int index) {
@Nullable
@Override
public String getDialogType() {
return executeMethod.execute(DriverCommand.GET_FEDCM_DIALOG_TYPE, null);
return executeMethod.executeOptional(DriverCommand.GET_FEDCM_DIALOG_TYPE, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class LocalExecuteMethod implements ExecuteMethod {
@Nullable
@Override
public <T> T execute(String commandName, @Nullable Map<String, ?> parameters) {
public Object execute(String commandName, @Nullable Map<String, ?> parameters) {
throw new WebDriverException("Cannot execute remote command: " + commandName);
}
}
5 changes: 2 additions & 3 deletions java/src/org/openqa/selenium/remote/RemoteExecuteMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ public RemoteExecuteMethod(RemoteWebDriver driver) {
this.driver = Require.nonNull("Remote WebDriver", driver);
}

@SuppressWarnings("unchecked")
@Override
public @Nullable <T> T execute(String commandName, @Nullable Map<String, ?> parameters) {
public @Nullable Object execute(String commandName, @Nullable Map<String, ?> parameters) {
Response response;

if (parameters == null || parameters.isEmpty()) {
Expand All @@ -42,7 +41,7 @@ public RemoteExecuteMethod(RemoteWebDriver driver) {
response = driver.execute(commandName, parameters);
}

return (T) response.getValue();
return response.getValue();
}

@Override
Expand Down
Loading