[java] specify nullability in package org.openqa.selenium.remote#17325
[java] specify nullability in package org.openqa.selenium.remote#17325asolntsev merged 6 commits intoSeleniumHQ:trunkfrom
org.openqa.selenium.remote#17325Conversation
|
Thank you, @asolntsev for this code suggestion. The support packages contain example code that many users find helpful, but they do not necessarily represent After reviewing the change, unless it is a critical fix or a feature that is needed for Selenium We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks. |
Review Summary by QodoSpecify nullability in Java bindings using JSpecify annotations
WalkthroughsDescriptionSpecify nullability in the Java bindings using JSpecify annotations * Mark everything as non-nullable by default using @NullMarked at package level across multiple packages * Add selective @Nullable annotations to specific fields, parameters, and return types that can be null * Replace manual null checks with utility methods like Require.nonNull() and requireNonNullElse() * Make DriverService abstract and refine nullability of its fields and methods * Extract PasswordAuthenticator class from JdkHttpClient for better code organization * Add query parameter utility methods to HttpRequest (getQueryString(), forEachQueryParameter(), getQueryParameters()) * Add new getHeader() method to HttpMessage with default value support * Make inner classes final where appropriate (e.g., in Route, UrlTemplate) * Update driver service implementations (Chrome, Firefox, Safari, Edge, IE) to make timeout parameter non-nullable * Add comprehensive test coverage for new functionality (PasswordAuthenticatorTest, HttpRequestTest) * Update multiple test classes with nullability annotations and improve test robustness * Add package-info.java files with @NullMarked annotation to 16 packages * Update BUILD.bazel files to include org.jspecify:jspecify dependency * Minor code cleanups and refactorings to improve null-safety analysis Partially implements #14291 File Changes1. java/src/org/openqa/selenium/remote/RemoteWebDriver.java
|
Code Review by Qodo
|
Review Summary by QodoSpecify nullability annotations in package
WalkthroughsDescriptionComprehensive nullability annotation implementation across the Java codebase in the org.openqa.selenium.remote package and related modules. **Key Changes:** • Added @NullMarked package-level annotations to establish non-nullable-by-default policy across multiple packages • Systematically added @Nullable annotations to fields, parameters, and return types that can be null • Replaced manual null checks with utility methods (Require.nonNull(), requireNonNull(), requireNonNullElse()) • Made DriverService abstract class with improved nullability handling • Extracted helper classes (PasswordAuthenticator) and methods for better code organization • Refactored query parameter handling with new utility methods (forEachQueryParameter(), getQueryString(), getQueryParameters()) • Added new test files for HttpRequest and PasswordAuthenticator classes • Updated multiple driver service classes to make timeout parameter non-nullable • Changed exception classes to have non-nullable parameters • Added jspecify dependency to build configurations • Minor code cleanups: removed unused imports, made inner classes static/final, fixed JavaDoc typos File Changes1. java/src/org/openqa/selenium/remote/RemoteWebDriver.java
|
Code Review by Qodo
|
f52d6ed to
1dc928d
Compare
* Mark everything as non-nullable by default, and * Mark only the needed methods/parameters as nullable. Partially implements SeleniumHQ#14291
…owser/websocket was already closed) Failure example: org.openqa.selenium.WebDriverException: java.io.IOException: Output closed Build info: version: '4.44.0-SNAPSHOT', revision: 'Unknown' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.1.0-44-cloud-amd64', java.version: '21.0.9' Driver info: driver.version: RemoteWebDriver at org.openqa.selenium.remote.http.jdk.JdkHttpClient$3.send(JdkHttpClient.java:325) at org.openqa.selenium.remote.http.WebSocket.sendText(WebSocket.java:32) at org.openqa.selenium.bidi.Connection.send(Connection.java:150) at org.openqa.selenium.bidi.Connection.clearListeners(Connection.java:245) at org.openqa.selenium.bidi.BiDi.clearListeners(BiDi.java:122) at org.openqa.selenium.bidi.BiDi.close(BiDi.java:50) at java.base/java.util.Optional.ifPresent(Optional.java:178) at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:483) at org.openqa.selenium.SessionHandlingTest.callingAnyOperationAfterClosingTheLastWindowShouldThrowAnException(SessionHandlingTest.java:60) Caused by: java.io.IOException: Output closed at java.net.http/jdk.internal.net.http.websocket.MessageEncoder.encodeText(MessageEncoder.java:145) at java.net.http/jdk.internal.net.http.websocket.TransportImpl$SendTask$1.onText(TransportImpl.java:376) at java.net.http/jdk.internal.net.http.websocket.TransportImpl$SendTask$1.onText(TransportImpl.java:367) at java.net.http/jdk.internal.net.http.websocket.MessageQueue.peek(MessageQueue.java:223) at java.net.http/jdk.internal.net.http.websocket.TransportImpl$SendTask.run(TransportImpl.java:555) at java.net.http/jdk.internal.net.http.common.SequentialScheduler$CompleteRestartableTask.run(SequentialScheduler.java:149) at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:207) at java.net.http/jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:280) at java.net.http/jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:233) at java.net.http/jdk.internal.net.http.websocket.TransportImpl.sendText(TransportImpl.java:149) at java.net.http/jdk.internal.net.http.websocket.WebSocketImpl.sendText(WebSocketImpl.java:192) at org.openqa.selenium.remote.http.jdk.JdkHttpClient$3.lambda$send$1(JdkHttpClient.java:276) at org.openqa.selenium.remote.http.jdk.JdkHttpClient$3.send(JdkHttpClient.java:315) at org.openqa.selenium.remote.http.WebSocket.sendText(WebSocket.java:32) at org.openqa.selenium.bidi.Connection.send(Connection.java:150) at org.openqa.selenium.bidi.Connection.clearListeners(Connection.java:245) at org.openqa.selenium.bidi.BiDi.clearListeners(BiDi.java:122) at org.openqa.selenium.bidi.BiDi.close(BiDi.java:50) at java.base/java.util.Optional.ifPresent(Optional.java:178) at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:483) at org.openqa.selenium.SessionHandlingTest.callingAnyOperationAfterClosingTheLastWindowShouldThrowAnException(SessionHandlingTest.java:60)
... after a test annotated with @NoDriverAfterTest. Usually such tests close the browser.
before performing actions inside iframe, be sure its content is fully loaded.
Sometimes it downloads file "file_1(1).txt" instead of the expected "file_1.txt".
🔗 Related Issues
Closes #14291
🔄 Types of changes