diff --git a/java/src/org/openqa/selenium/interactions/Actions.java b/java/src/org/openqa/selenium/interactions/Actions.java index ac6671e75d978..60ad28c70c420 100644 --- a/java/src/org/openqa/selenium/interactions/Actions.java +++ b/java/src/org/openqa/selenium/interactions/Actions.java @@ -30,6 +30,8 @@ import java.util.Objects; import java.util.Set; import java.util.function.IntConsumer; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.PointerInput.Origin; @@ -44,6 +46,7 @@ * *

Call {@link #perform()} at the end of the method chain to actually perform the actions. */ +@NullMarked public class Actions { private final WebDriver driver; @@ -51,9 +54,9 @@ public class Actions { // W3C private final Map sequences = new HashMap<>(); - private PointerInput activePointer; - private KeyInput activeKeyboard; - private WheelInput activeWheel; + private @Nullable PointerInput activePointer; + private @Nullable KeyInput activeKeyboard; + private @Nullable WheelInput activeWheel; private Duration actionDuration; public Actions(WebDriver driver) { @@ -537,21 +540,21 @@ public KeyInput getActiveKeyboard() { if (this.activeKeyboard == null) { setActiveKeyboard("default keyboard"); } - return this.activeKeyboard; + return Require.nonNull("ActiveKeyboard", this.activeKeyboard); } public PointerInput getActivePointer() { if (this.activePointer == null) { setActivePointer(PointerInput.Kind.MOUSE, "default mouse"); } - return this.activePointer; + return Require.nonNull("ActivePointer", this.activePointer); } public WheelInput getActiveWheel() { if (this.activeWheel == null) { setActiveWheel("default wheel"); } - return this.activeWheel; + return Require.nonNull("ActiveWheel", this.activeWheel); } public Duration getActionDuration() { diff --git a/java/src/org/openqa/selenium/interactions/Pause.java b/java/src/org/openqa/selenium/interactions/Pause.java index 12d5012cb62c6..e9b7aeec35eba 100644 --- a/java/src/org/openqa/selenium/interactions/Pause.java +++ b/java/src/org/openqa/selenium/interactions/Pause.java @@ -22,8 +22,10 @@ import java.time.Duration; import java.util.HashMap; import java.util.Map; +import org.jspecify.annotations.NullMarked; /** Indicates that a given {@link InputSource} should pause for a given duration. */ +@NullMarked public class Pause extends Interaction implements Encodable { private final Duration duration; diff --git a/java/src/org/openqa/selenium/interactions/Sequence.java b/java/src/org/openqa/selenium/interactions/Sequence.java index 4ce04c859dd89..61db21eb8b1cb 100644 --- a/java/src/org/openqa/selenium/interactions/Sequence.java +++ b/java/src/org/openqa/selenium/interactions/Sequence.java @@ -22,6 +22,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.jspecify.annotations.NullMarked; /** * A sequence of action objects for a given {@link InputSource} for use with the W3C actions = new LinkedList<>(); diff --git a/java/src/org/openqa/selenium/interactions/WheelInput.java b/java/src/org/openqa/selenium/interactions/WheelInput.java index 9febb44d2228c..ae0e4dc273067 100644 --- a/java/src/org/openqa/selenium/interactions/WheelInput.java +++ b/java/src/org/openqa/selenium/interactions/WheelInput.java @@ -24,6 +24,8 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.Point; import org.openqa.selenium.WebElement; import org.openqa.selenium.WrapsElement; @@ -33,11 +35,12 @@ * Models a wheel input * source. */ +@NullMarked public class WheelInput implements InputSource, Encodable { private final String name; - public WheelInput(String name) { + public WheelInput(@Nullable String name) { this.name = Optional.ofNullable(name).orElse(UUID.randomUUID().toString()); }