You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In this PR I'm adding nullness annotations for interfaces:
WrapsDriver
WrapsElement
None of the methods in these wrappers can return a null value
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
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
import org.jspecify.annotations.NullMarked;
/**
* This interface indicates that the implementing class knows about the driver that contains it and
* can export it.
+ *+ * The {@code @NullMarked} annotation indicates that null-checking is enabled for this interface.
*/
@NullMarked
Apply this suggestion
Suggestion importance[1-10]: 8
Why: Providing a JavaDoc comment explaining the @NullMarked annotation improves maintainability by making the code more understandable, especially for developers unfamiliar with this annotation.
8
Add a JavaDoc comment to the interface method explaining its purpose and return value
Consider adding a brief JavaDoc comment to the getWrappedElement() method to explain its purpose and any potential null behavior.
@NullMarked
@FunctionalInterface
public interface WrapsElement {
+ /**+ * Returns the underlying WebElement wrapped by this instance.+ *+ * @return The wrapped WebElement, which should not be null.+ */
WebElement getWrappedElement();
}
Apply this suggestion
Suggestion importance[1-10]: 8
Why: Adding a JavaDoc comment enhances maintainability by clearly documenting the method's purpose and expected behavior, which is valuable for developers interacting with this interface.
8
Enhancement
Add a nullable annotation to the return type of the interface method
Consider adding a @Nullable annotation to the return type of the method in the WrapsDriver interface to explicitly indicate whether the returned driver can be null or not.
@NullMarked
@FunctionalInterface
public interface WrapsDriver {
/**
* @return The driver that contains this element.
+ */+ @Nullable+ WebDriver getWrappedDriver();
Apply this suggestion
Suggestion importance[1-10]: 7
Why: Adding a @Nullable annotation could improve code clarity by explicitly indicating the nullability of the return type, which is beneficial for developers using this interface.
7
Add a non-null annotation to the return type of the interface method
Consider adding a @Nullable or @NonNull annotation to the return type of the getWrappedElement() method to explicitly indicate whether the returned element can be null or not.
Why: Adding a @NonNull annotation would enhance code clarity by explicitly stating that the return value should not be null, which is useful for developers using this interface.
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:
WrapsDriver
WrapsElement
None of the methods in these wrappers can return a null value
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, documentation
Description
@NullMarked
annotations to theWrapsDriver
andWrapsElement
interfaces.Changes walkthrough 📝
WrapsDriver.java
Add JSpecify nullness annotations to WrapsDriver
java/src/org/openqa/selenium/WrapsDriver.java
@NullMarked
annotation to theWrapsDriver
interface.org.jspecify.annotations.NullMarked
.WrapsElement.java
Add JSpecify nullness annotations to WrapsElement
java/src/org/openqa/selenium/WrapsElement.java
@NullMarked
annotation to theWrapsElement
interface.org.jspecify.annotations.NullMarked
.