Skip to content

Commit b60fb8e

Browse files
mk868pujaganidiemol
authored
[java] JSpecify annotations for immutable models and enums (SeleniumHQ#14395)
Co-authored-by: Puja Jagani <[email protected]> Co-authored-by: Diego Molina <[email protected]>
1 parent 269a7f6 commit b60fb8e

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

java/src/org/openqa/selenium/Dimension.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
package org.openqa.selenium;
1919

2020
import java.util.Objects;
21+
import org.jspecify.annotations.NullMarked;
22+
import org.jspecify.annotations.Nullable;
2123

2224
/** Similar to Point - implement locally to avoid depending on GWT. */
25+
@NullMarked
2326
public class Dimension {
2427
public final int width;
2528
public final int height;
@@ -38,7 +41,7 @@ public int getHeight() {
3841
}
3942

4043
@Override
41-
public boolean equals(Object o) {
44+
public boolean equals(@Nullable Object o) {
4245
if (!(o instanceof Dimension)) {
4346
return false;
4447
}

java/src/org/openqa/selenium/Keys.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package org.openqa.selenium;
1919

2020
import java.util.Arrays;
21+
import org.jspecify.annotations.NullMarked;
22+
import org.jspecify.annotations.Nullable;
2123

2224
/**
2325
* Representations of pressable keys that aren't text. These are stored in the Unicode PUA (Private
@@ -26,6 +28,7 @@
2628
* @see <a
2729
* href="http://www.google.com.au/search?&amp;q=unicode+pua&amp;btnK=Search">http://www.google.com.au/search?&amp;q=unicode+pua&amp;btnK=Search</a>
2830
*/
31+
@NullMarked
2932
public enum Keys implements CharSequence {
3033
NULL('\uE000'),
3134
CANCEL('\uE001'), // ^break
@@ -180,7 +183,7 @@ public static String chord(Iterable<CharSequence> value) {
180183
* @param key unicode character code
181184
* @return special key linked to the character code, or null if character is not a special key
182185
*/
183-
public static Keys getKeyFromUnicode(char key) {
186+
public static @Nullable Keys getKeyFromUnicode(char key) {
184187
for (Keys unicodeKey : values()) {
185188
if (unicodeKey.charAt(0) == key) {
186189
return unicodeKey;

java/src/org/openqa/selenium/Point.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
package org.openqa.selenium;
1919

2020
import java.util.Objects;
21+
import org.jspecify.annotations.NullMarked;
22+
import org.jspecify.annotations.Nullable;
2123

2224
/** A copy of java.awt.Point, to remove dependency on awt. */
25+
@NullMarked
2326
public class Point {
2427
public int x;
2528
public int y;
@@ -42,7 +45,7 @@ public Point moveBy(int xOffset, int yOffset) {
4245
}
4346

4447
@Override
45-
public boolean equals(Object o) {
48+
public boolean equals(@Nullable Object o) {
4649
if (!(o instanceof Point)) {
4750
return false;
4851
}

java/src/org/openqa/selenium/Rectangle.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919

2020
import java.util.Map;
2121
import java.util.Objects;
22+
import org.jspecify.annotations.NullMarked;
23+
import org.jspecify.annotations.Nullable;
2224

25+
@NullMarked
2326
public class Rectangle {
2427

2528
public final int x;
@@ -70,7 +73,7 @@ private Map<String, Object> toJson() {
7073
}
7174

7275
@Override
73-
public boolean equals(Object o) {
76+
public boolean equals(@Nullable Object o) {
7477
if (this == o) {
7578
return true;
7679
}

java/src/org/openqa/selenium/UsernameAndPassword.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
package org.openqa.selenium;
1919

2020
import java.util.function.Supplier;
21+
import org.jspecify.annotations.NullMarked;
2122
import org.openqa.selenium.internal.Require;
2223

2324
/** A combination of username and password to use when authenticating a browser with a website. */
25+
@NullMarked
2426
public class UsernameAndPassword implements Credentials {
2527

2628
private final String username;

0 commit comments

Comments
 (0)