Skip to content

Commit 5e2a630

Browse files
authored
[java] Add JSpecify annotations for WebDriver and 3 other interfaces (#14371)
1 parent 9bd82f2 commit 5e2a630

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

java/src/org/openqa/selenium/JavascriptExecutor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.Collections;
2121
import java.util.Set;
2222
import java.util.stream.Collectors;
23+
import org.jspecify.annotations.NullMarked;
24+
import org.jspecify.annotations.Nullable;
2325
import org.openqa.selenium.internal.Require;
2426

2527
/**
@@ -30,6 +32,7 @@
3032
* request or when trying to access another frame. Most times when troubleshooting failure it's best
3133
* to view the browser's console after executing the WebDriver request.
3234
*/
35+
@NullMarked
3336
public interface JavascriptExecutor {
3437
/**
3538
* Executes JavaScript in the context of the currently selected frame or window. The script
@@ -63,7 +66,7 @@ public interface JavascriptExecutor {
6366
* @param args The arguments to the script. May be empty
6467
* @return One of Boolean, Long, Double, String, List, Map or WebElement. Or null.
6568
*/
66-
Object executeScript(String script, Object... args);
69+
@Nullable Object executeScript(String script, @Nullable Object... args);
6770

6871
/**
6972
* Execute an asynchronous piece of JavaScript in the context of the currently selected frame or
@@ -139,7 +142,7 @@ public interface JavascriptExecutor {
139142
* @return One of Boolean, Long, String, List, Map, WebElement, or null.
140143
* @see WebDriver.Timeouts#scriptTimeout(java.time.Duration)
141144
*/
142-
Object executeAsyncScript(String script, Object... args);
145+
@Nullable Object executeAsyncScript(String script, @Nullable Object... args);
143146

144147
/**
145148
* Commonly used scripts may be "pinned" to the WebDriver session, allowing them to be called
@@ -186,7 +189,7 @@ default Set<ScriptKey> getPinnedScripts() {
186189
*
187190
* @see #executeScript(String, Object...)
188191
*/
189-
default Object executeScript(ScriptKey key, Object... args) {
192+
default @Nullable Object executeScript(ScriptKey key, @Nullable Object... args) {
190193
Require.stateCondition(
191194
key instanceof UnpinnedScriptKey, "Script key should have been generated by this driver");
192195

java/src/org/openqa/selenium/OutputType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
import java.nio.file.Files;
2323
import java.nio.file.Path;
2424
import java.util.Base64;
25+
import org.jspecify.annotations.NullMarked;
2526

2627
/**
2728
* Defines the output type for a screenshot.
2829
*
2930
* @see TakesScreenshot
3031
* @param <T> Type for the screenshot output.
3132
*/
33+
@NullMarked
3234
public interface OutputType<T> {
3335
/** Obtain the screenshot as base64 data. */
3436
OutputType<String> BASE64 =

java/src/org/openqa/selenium/TakesScreenshot.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// under the License.
1717
package org.openqa.selenium;
1818

19+
import org.jspecify.annotations.NullMarked;
20+
1921
/**
2022
* Indicates a driver or an HTML element that can capture a screenshot and store it in different
2123
* ways.
@@ -29,6 +31,7 @@
2931
*
3032
* @see OutputType
3133
*/
34+
@NullMarked
3235
public interface TakesScreenshot {
3336
/**
3437
* Capture the screenshot and store it in the specified location.

java/src/org/openqa/selenium/WebDriver.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.List;
2323
import java.util.Set;
2424
import java.util.concurrent.TimeUnit;
25+
import org.jspecify.annotations.NullMarked;
26+
import org.jspecify.annotations.Nullable;
2527
import org.openqa.selenium.logging.LoggingPreferences;
2628
import org.openqa.selenium.logging.Logs;
2729

@@ -46,6 +48,7 @@
4648
* <p>Most implementations of this interface follow <a href="https://w3c.github.io/webdriver/">W3C
4749
* WebDriver specification</a>
4850
*/
51+
@NullMarked
4952
public interface WebDriver extends SearchContext {
5053
// Navigation
5154

@@ -74,7 +77,7 @@ public interface WebDriver extends SearchContext {
7477
*
7578
* @return The URL of the page currently loaded in the browser
7679
*/
77-
String getCurrentUrl();
80+
@Nullable String getCurrentUrl();
7881

7982
// General properties
8083

@@ -87,7 +90,7 @@ public interface WebDriver extends SearchContext {
8790
* @return The title of the current page, with leading and trailing whitespace stripped, or null
8891
* if one is not already set
8992
*/
90-
String getTitle();
93+
@Nullable String getTitle();
9194

9295
/**
9396
* Find all elements within the current page using the given mechanism. This method is affected by
@@ -142,7 +145,7 @@ public interface WebDriver extends SearchContext {
142145
*
143146
* @return The source of the current page
144147
*/
145-
String getPageSource();
148+
@Nullable String getPageSource();
146149

147150
/**
148151
* Close the current window, quitting the browser if it's the last window currently open.
@@ -261,7 +264,7 @@ interface Options {
261264
* @param name the name of the cookie
262265
* @return the cookie, or null if no cookie with the given name is present
263266
*/
264-
Cookie getCookieNamed(String name);
267+
@Nullable Cookie getCookieNamed(String name);
265268

266269
/**
267270
* @return the interface for managing driver timeouts.

0 commit comments

Comments
 (0)