[java] Add JSpecify annotations for WebDriver and 3 other interfaces #14371
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
User description
Description
In this PR I'm adding nullness annotations for interfaces:
WebDriver
TakesScreenshot
OutputType
JavascriptExecutor
WebDriver
Null values occur only in methods:
String getTitle()
- the JavaDoc says: "return (...) null if one is not already set" -> marked as@Nullable
Cookie Options#getCookieNamed(String name)
- if there is no cookie with the specified name, returns a null value -> marked as@Nullable
String getPageSource()
- I'm not sure about that looking at W3C WebDriver specification, as far as I can see in implementations, returning a null value is possible -> marked as@Nullable
String getCurrentUrl()
- From the HtmlUnit driver implementation, a null value is possible when the page is not loaded -> marked as@Nullable
Notes:
RemoteWebDriver#getTitle()
implementation actually returns an empty string when the title is nullTakesScreenshot
&OutputType
These interfaces are closely related to each other, there are no null values.
JavascriptExecutor
Null values occur only in methods:
Object executeScript(String script, Object... args)
Object executeAsyncScript(String script, Object... args)
Object executeScript(ScriptKey key, Object... args)
The result can be null, so the
Object
return type marked as@Nullable
.The elements in the
args
array can be null (args
itself cannot be null), so the array argument type marked as@Nullable
.Motivation and Context
The JSpecify nullness annotations will give developers better exposure to potential problems with their code to avoid NullPointerExceptions.
Related issue: #14291
Types of changes
Checklist
PR Type
Enhancement
Description
WebDriver
,TakesScreenshot
,OutputType
, andJavascriptExecutor
interfaces.@Nullable
where null values are possible.Changes walkthrough 📝
JavascriptExecutor.java
Add JSpecify annotations to JavascriptExecutor interface
java/src/org/openqa/selenium/JavascriptExecutor.java
@NullMarked
annotation to the interface.@Nullable
where applicable.OutputType.java
Add JSpecify annotations to OutputType interface
java/src/org/openqa/selenium/OutputType.java
@NullMarked
annotation to the interface.TakesScreenshot.java
Add JSpecify annotations to TakesScreenshot interface
java/src/org/openqa/selenium/TakesScreenshot.java
@NullMarked
annotation to the interface.WebDriver.java
Add JSpecify annotations to WebDriver interface
java/src/org/openqa/selenium/WebDriver.java
@NullMarked
annotation to the interface.@Nullable
where applicable.