Skip to content

Commit 6141259

Browse files
mk868VietND96
andauthored
[java] Add nullness for interactions v2 (#15106)
Co-authored-by: Viet Nguyen Duc <[email protected]>
1 parent 4d02e6b commit 6141259

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

java/src/org/openqa/selenium/interactions/Actions.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import java.util.Objects;
3131
import java.util.Set;
3232
import java.util.function.IntConsumer;
33+
import org.jspecify.annotations.NullMarked;
34+
import org.jspecify.annotations.Nullable;
3335
import org.openqa.selenium.WebDriver;
3436
import org.openqa.selenium.WebElement;
3537
import org.openqa.selenium.interactions.PointerInput.Origin;
@@ -44,16 +46,17 @@
4446
*
4547
* <p>Call {@link #perform()} at the end of the method chain to actually perform the actions.
4648
*/
49+
@NullMarked
4750
public class Actions {
4851

4952
private final WebDriver driver;
5053

5154
// W3C
5255
private final Map<InputSource, Sequence> sequences = new HashMap<>();
5356

54-
private PointerInput activePointer;
55-
private KeyInput activeKeyboard;
56-
private WheelInput activeWheel;
57+
private @Nullable PointerInput activePointer;
58+
private @Nullable KeyInput activeKeyboard;
59+
private @Nullable WheelInput activeWheel;
5760
private Duration actionDuration;
5861

5962
public Actions(WebDriver driver) {
@@ -537,21 +540,21 @@ public KeyInput getActiveKeyboard() {
537540
if (this.activeKeyboard == null) {
538541
setActiveKeyboard("default keyboard");
539542
}
540-
return this.activeKeyboard;
543+
return Require.nonNull("ActiveKeyboard", this.activeKeyboard);
541544
}
542545

543546
public PointerInput getActivePointer() {
544547
if (this.activePointer == null) {
545548
setActivePointer(PointerInput.Kind.MOUSE, "default mouse");
546549
}
547-
return this.activePointer;
550+
return Require.nonNull("ActivePointer", this.activePointer);
548551
}
549552

550553
public WheelInput getActiveWheel() {
551554
if (this.activeWheel == null) {
552555
setActiveWheel("default wheel");
553556
}
554-
return this.activeWheel;
557+
return Require.nonNull("ActiveWheel", this.activeWheel);
555558
}
556559

557560
public Duration getActionDuration() {

java/src/org/openqa/selenium/interactions/Pause.java

+2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
import java.time.Duration;
2323
import java.util.HashMap;
2424
import java.util.Map;
25+
import org.jspecify.annotations.NullMarked;
2526

2627
/** Indicates that a given {@link InputSource} should pause for a given duration. */
28+
@NullMarked
2729
public class Pause extends Interaction implements Encodable {
2830

2931
private final Duration duration;

java/src/org/openqa/selenium/interactions/Sequence.java

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.LinkedList;
2323
import java.util.List;
2424
import java.util.Map;
25+
import org.jspecify.annotations.NullMarked;
2526

2627
/**
2728
* A sequence of action objects for a given {@link InputSource} for use with the W3C <a
@@ -30,6 +31,7 @@
3031
* Interaction}s, with the first item in each sequence being executed at the same time, then the
3132
* second, and so on, until all interactions in all sequences have been executed.
3233
*/
34+
@NullMarked
3335
public class Sequence implements Encodable {
3436

3537
private final List<Encodable> actions = new LinkedList<>();

java/src/org/openqa/selenium/interactions/WheelInput.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.Map;
2525
import java.util.Optional;
2626
import java.util.UUID;
27+
import org.jspecify.annotations.NullMarked;
28+
import org.jspecify.annotations.Nullable;
2729
import org.openqa.selenium.Point;
2830
import org.openqa.selenium.WebElement;
2931
import org.openqa.selenium.WrapsElement;
@@ -33,11 +35,12 @@
3335
* Models a <a href="https://www.w3.org/TR/webdriver/#dfn-wheel-input-source">wheel input
3436
* source</a>.
3537
*/
38+
@NullMarked
3639
public class WheelInput implements InputSource, Encodable {
3740

3841
private final String name;
3942

40-
public WheelInput(String name) {
43+
public WheelInput(@Nullable String name) {
4144
this.name = Optional.ofNullable(name).orElse(UUID.randomUUID().toString());
4245
}
4346

0 commit comments

Comments
 (0)