Skip to content

Commit 4b9879c

Browse files
mk868diemol
authored andcommitted
[java] Add nullness for exceptions (SeleniumHQ#15081)
Co-authored-by: Diego Molina <[email protected]>
1 parent 78d107b commit 4b9879c

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

Diff for: java/src/org/openqa/selenium/NoSuchElementException.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,28 @@
1717

1818
package org.openqa.selenium;
1919

20+
import org.jspecify.annotations.NullMarked;
21+
import org.jspecify.annotations.Nullable;
22+
2023
/**
2124
* Thrown by {@link WebDriver#findElement(By) WebDriver.findElement(By by)} and {@link
2225
* WebElement#findElement(By by) WebElement.findElement(By by)}.
2326
*/
27+
@NullMarked
2428
public class NoSuchElementException extends NotFoundException {
2529

2630
private static final String SUPPORT_URL = BASE_SUPPORT_URL + "#no-such-element-exception";
2731

28-
public NoSuchElementException(String reason) {
32+
public NoSuchElementException(@Nullable String reason) {
2933
super(reason);
3034
}
3135

32-
public NoSuchElementException(String reason, Throwable cause) {
36+
public NoSuchElementException(@Nullable String reason, @Nullable Throwable cause) {
3337
super(reason, cause);
3438
}
3539

3640
@Override
37-
public String getSupportUrl() {
41+
public @Nullable String getSupportUrl() {
3842
return SUPPORT_URL;
3943
}
4044
}

Diff for: java/src/org/openqa/selenium/NotFoundException.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@
1717

1818
package org.openqa.selenium;
1919

20+
import org.jspecify.annotations.NullMarked;
21+
import org.jspecify.annotations.Nullable;
22+
23+
@NullMarked
2024
public class NotFoundException extends WebDriverException {
2125

2226
public NotFoundException() {}
2327

24-
public NotFoundException(String message) {
28+
public NotFoundException(@Nullable String message) {
2529
super(message);
2630
}
2731

28-
public NotFoundException(String message, Throwable cause) {
32+
public NotFoundException(@Nullable String message, @Nullable Throwable cause) {
2933
super(message, cause);
3034
}
3135

32-
public NotFoundException(Throwable cause) {
36+
public NotFoundException(@Nullable Throwable cause) {
3337
super(cause);
3438
}
3539
}

Diff for: java/src/org/openqa/selenium/StaleElementReferenceException.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,28 @@
1717

1818
package org.openqa.selenium;
1919

20+
import org.jspecify.annotations.NullMarked;
21+
import org.jspecify.annotations.Nullable;
22+
2023
/**
2124
* Indicates that a reference to an element is now "stale" --- the element no longer appears on the
2225
* DOM of the page.
2326
*/
27+
@NullMarked
2428
public class StaleElementReferenceException extends WebDriverException {
2529

2630
private static final String SUPPORT_URL = BASE_SUPPORT_URL + "#stale-element-reference-exception";
2731

28-
public StaleElementReferenceException(String message) {
32+
public StaleElementReferenceException(@Nullable String message) {
2933
super(message);
3034
}
3135

32-
public StaleElementReferenceException(String message, Throwable cause) {
36+
public StaleElementReferenceException(@Nullable String message, @Nullable Throwable cause) {
3337
super(message, cause);
3438
}
3539

3640
@Override
37-
public String getSupportUrl() {
41+
public @Nullable String getSupportUrl() {
3842
return SUPPORT_URL;
3943
}
4044
}

Diff for: java/src/org/openqa/selenium/WebDriverException.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
import java.util.concurrent.ConcurrentHashMap;
2323
import java.util.stream.Collectors;
2424
import java.util.stream.Stream;
25+
import org.jspecify.annotations.NullMarked;
26+
import org.jspecify.annotations.Nullable;
2527
import org.openqa.selenium.net.HostIdentifier;
2628

29+
@NullMarked
2730
public class WebDriverException extends RuntimeException {
2831

2932
public static final String SESSION_ID = "Session ID";
@@ -37,15 +40,15 @@ public WebDriverException() {
3740
super();
3841
}
3942

40-
public WebDriverException(String message) {
43+
public WebDriverException(@Nullable String message) {
4144
super(message);
4245
}
4346

44-
public WebDriverException(Throwable cause) {
47+
public WebDriverException(@Nullable Throwable cause) {
4548
super(cause);
4649
}
4750

48-
public WebDriverException(String message, Throwable cause) {
51+
public WebDriverException(@Nullable String message, @Nullable Throwable cause) {
4952
super(message, cause);
5053
}
5154

@@ -58,7 +61,7 @@ public WebDriverException(String message, Throwable cause) {
5861
* @return the detail message string of this exception.
5962
*/
6063
@Override
61-
public String getMessage() {
64+
public @Nullable String getMessage() {
6265
return getCause() instanceof WebDriverException
6366
? super.getMessage()
6467
: createMessage(super.getMessage());
@@ -70,11 +73,11 @@ public String getMessage() {
7073
* @return the simple message string of this exception.
7174
* @see #getMessage()
7275
*/
73-
public String getRawMessage() {
76+
public @Nullable String getRawMessage() {
7477
return super.getMessage();
7578
}
7679

77-
private String createMessage(String originalMessageString) {
80+
private String createMessage(@Nullable String originalMessageString) {
7881
String supportMessage =
7982
Optional.ofNullable(getSupportUrl())
8083
.map(url -> String.format("For documentation on this error, please visit: %s", url))
@@ -105,7 +108,7 @@ public static String getHostInformation() {
105108
HostIdentifier.getHostName(), HostIdentifier.getHostAddress());
106109
}
107110

108-
public String getSupportUrl() {
111+
public @Nullable String getSupportUrl() {
109112
return null;
110113
}
111114

0 commit comments

Comments
 (0)