Skip to content

Conversation

@iampopovich
Copy link
Contributor

@iampopovich iampopovich commented Dec 28, 2025

User description

🔗 Related Issues

relates to #14291

💥 What does this PR do?

This pull request primarily removes the use of the @NullMarked annotation from several classes and interfaces in the Selenium Java codebase. The @NullMarked annotation, which is part of the jspecify library, was previously used to indicate that all types in the annotated scope are non-null by default unless otherwise specified. Its removal simplifies the code and may reflect a change in how nullability is handled or annotated in the project. Additionally, there is a minor build dependency update.

Key changes:

Nullability annotation removal:

  • Removed all instances of the @NullMarked annotation and related import statements from key classes and interfaces, including but not limited to: By, Capabilities, Cookie, Dimension, HasCapabilities, ImmutableCapabilities, InvalidCookieDomainException, JavascriptExecutor, Keys, MutableCapabilities, NoSuchElementException, NotFoundException, OutputType, PageLoadStrategy, PersistentCapabilities, Platform, Point, Proxy, and Rectangle. This change affects both the class/interface declarations and the import sections. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24]

Build configuration:

  • Added a new dependency on //java/src/org/openqa/selenium:core to the java_binary target in java/src/dev/selenium/tools/javadoc/BUILD.bazel.

🔧 Implementation Notes

💡 Additional Considerations

🔄 Types of changes

  • Cleanup (formatting, renaming)

PR Type

Enhancement


Description

  • Remove @NullMarked annotations from 30+ classes and interfaces

  • Add package-level @NullMarked annotations via package-info.java files

  • Add explicit @Nullable annotations to specific method return types

  • Update build dependencies to include jspecify artifact


Diagram Walkthrough

flowchart LR
  A["Class-level @NullMarked<br/>annotations"] -->|Remove from 30+ classes| B["Package-level<br/>@NullMarked"]
  B -->|via package-info.java| C["org.openqa.selenium<br/>org.openqa.selenium.chromium<br/>org.openqa.selenium.devtools"]
  D["Method return types"] -->|Add explicit| E["@Nullable annotations"]
  F["Build files"] -->|Add dependency| G["jspecify artifact"]
Loading

File Walkthrough

Relevant files
Cleanup
33 files
By.java
Remove @NullMarked annotation from By class                           
+0/-2     
Capabilities.java
Remove @NullMarked annotation from interface                         
+0/-2     
Cookie.java
Remove @NullMarked annotation from Cookie class                   
+0/-2     
Dimension.java
Remove @NullMarked annotation from Dimension class             
+0/-2     
HasCapabilities.java
Remove @NullMarked annotation from interface                         
+0/-3     
ImmutableCapabilities.java
Remove @NullMarked annotation from class                                 
+0/-2     
InvalidCookieDomainException.java
Remove @NullMarked annotation from exception                         
+0/-2     
JavascriptExecutor.java
Remove @NullMarked annotation from interface                         
+0/-2     
Keys.java
Remove @NullMarked annotation from enum                                   
+0/-2     
MutableCapabilities.java
Remove @NullMarked annotation from class                                 
+0/-2     
NoSuchElementException.java
Remove @NullMarked annotation from exception                         
+0/-2     
NotFoundException.java
Remove @NullMarked annotation from exception                         
+0/-2     
OutputType.java
Remove @NullMarked annotation from interface                         
+0/-2     
PageLoadStrategy.java
Remove @NullMarked annotation from enum                                   
+0/-2     
PersistentCapabilities.java
Remove @NullMarked annotation from class                                 
+0/-2     
Platform.java
Remove @NullMarked annotation from enum                                   
+0/-2     
Point.java
Remove @NullMarked annotation from class                                 
+0/-2     
Proxy.java
Remove @NullMarked annotation from class                                 
+0/-2     
Rectangle.java
Remove @NullMarked annotation from class                                 
+0/-2     
ScriptKey.java
Remove @NullMarked annotation from class                                 
+0/-2     
SearchContext.java
Remove @NullMarked annotation from interface                         
+0/-2     
StaleElementReferenceException.java
Remove @NullMarked annotation from exception                         
+0/-2     
TakesScreenshot.java
Remove @NullMarked annotation from interface                         
+0/-3     
UnableToSetCookieException.java
Remove @NullMarked annotation from exception                         
+0/-2     
UnexpectedAlertBehaviour.java
Remove @NullMarked annotation from enum                                   
+0/-2     
UnpinnedScriptKey.java
Remove @NullMarked annotation from class                                 
+0/-2     
UsernameAndPassword.java
Remove @NullMarked annotation from class                                 
+0/-2     
WebDriver.java
Remove @NullMarked annotation from interface                         
+0/-2     
WebDriverException.java
Remove @NullMarked annotation from class                                 
+0/-2     
WebElement.java
Remove @NullMarked annotation from interface                         
+0/-2     
WindowType.java
Remove @NullMarked annotation from enum                                   
+0/-2     
WrapsDriver.java
Remove @NullMarked annotation from interface                         
+0/-3     
WrapsElement.java
Remove @NullMarked annotation from interface                         
+0/-3     
Enhancement
7 files
ChromiumDriverLogLevel.java
Add @Nullable to fromString method return type                     
+2/-0     
ChromiumOptions.java
Add @Nullable to getExtraCapability method return               
+2/-0     
package-info.java
Create package-info with @NullMarked annotation                   
+21/-0   
CdpClientGenerator.java
Add @Nullable to toTypeDeclaration method return                 
+2/-0     
ConverterFunctions.java
Add @Nullable annotations to map and empty methods             
+6/-4     
package-info.java
Create package-info with @NullMarked annotation                   
+21/-0   
package-info.java
Create package-info with @NullMarked annotation                   
+21/-0   
Configuration changes
1 files
BUILD.bazel
Add core dependency to javadoc binary                                       
+1/-0     
Dependencies
1 files
BUILD.bazel
Add jspecify artifact dependency to generator                       
+1/-0     

@iampopovich iampopovich self-assigned this Dec 28, 2025
@selenium-ci selenium-ci added C-java Java Bindings B-build Includes scripting, bazel and CI integrations B-devtools Includes everything BiDi or Chrome DevTools related labels Dec 28, 2025
@iampopovich iampopovich marked this pull request as ready for review December 28, 2025 10:43
Copilot AI review requested due to automatic review settings December 28, 2025 10:43
@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Dec 28, 2025

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Dec 28, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
High-level
Centralize null-safety annotations using package-info

The PR centralizes null-safety by moving @NullMarked annotations from individual
classes to package-info.java files. This pattern should be applied consistently
to other packages in the codebase to improve maintainability.

Examples:

java/src/org/openqa/selenium/package-info.java [18-21]
@NullMarked
package org.openqa.selenium;

import org.jspecify.annotations.NullMarked;
java/src/org/openqa/selenium/By.java [44]
public abstract class By {

Solution Walkthrough:

Before:

// In a hypothetical file: .../selenium/unmodified/AnotherClass.java
package org.openqa.selenium.unmodified;

import org.jspecify.annotations.NullMarked;
// ... other imports

@NullMarked
public class AnotherClass {
  // class implementation
}

// No package-info.java exists for this package.

After:

// In file: .../selenium/unmodified/AnotherClass.java
package org.openqa.selenium.unmodified;

// ... other imports

// @NullMarked annotation is removed
public class AnotherClass {
  // class implementation
}

// New file: .../selenium/unmodified/package-info.java
@NullMarked
package org.openqa.selenium.unmodified;

import org.jspecify.annotations.NullMarked;
Suggestion importance[1-10]: 5

__

Why: The suggestion correctly identifies the PR's refactoring pattern and proposes extending it for consistency, which is a valid point for improving overall code quality, though not a critical flaw in the current changes.

Low
  • Update

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds package-level @NullMarked annotations to three Selenium Java packages (org.openqa.selenium, org.openqa.selenium.devtools, and org.openqa.selenium.chromium) and adds explicit @Nullable annotations to methods and parameters that can return or accept null values. The change moves nullability semantics from individual class-level annotations to package-level annotations, while classes that previously had @NullMarked annotations now inherit this behavior from their package. Additionally, it adds explicit @Nullable markers where nullability needs to be explicitly declared.

  • Added package-level @NullMarked annotations via new package-info.java files for three packages
  • Added @Nullable annotations to methods/parameters in devtools and chromium packages that can handle null values
  • Removed individual @NullMarked annotations from 20+ classes/interfaces since they now inherit from package-level annotations
  • Updated build dependencies to include jspecify for compilation

Reviewed changes

Copilot reviewed 42 out of 42 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
java/src/org/openqa/selenium/package-info.java Adds package-level @NullMarked annotation for the selenium core package
java/src/org/openqa/selenium/devtools/package-info.java Adds package-level @NullMarked annotation for the devtools package
java/src/org/openqa/selenium/chromium/package-info.java Adds package-level @NullMarked annotation for the chromium package
java/src/org/openqa/selenium/devtools/ConverterFunctions.java Adds @Nullable annotations to return types and parameters that can be null
java/src/org/openqa/selenium/devtools/CdpClientGenerator.java Adds @Nullable annotation to method that returns null
java/src/org/openqa/selenium/chromium/ChromiumOptions.java Adds @Nullable annotation to method that can return null
java/src/org/openqa/selenium/chromium/ChromiumDriverLogLevel.java Adds @Nullable annotation to method that can return null
java/src/org/openqa/selenium/devtools/BUILD.bazel Adds jspecify dependency for devtools build
java/src/dev/selenium/tools/javadoc/BUILD.bazel Adds selenium core dependency for javadoc build
Various core selenium classes Removes redundant @NullMarked annotations now inherited from package-level

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…m, devtools, and selenium packages after review
…chromium, devtools, and selenium packages after review"

This reverts commit 52ad8fe.
@iampopovich
Copy link
Contributor Author

@asolntsev any suggestions here ?

Copy link
Contributor

@asolntsev asolntsev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@asolntsev asolntsev added this to the 4.40.0 milestone Jan 2, 2026
@iampopovich iampopovich merged commit f6b2013 into SeleniumHQ:trunk Jan 2, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-build Includes scripting, bazel and CI integrations B-devtools Includes everything BiDi or Chrome DevTools related C-java Java Bindings Review effort 2/5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants