Skip to content

[java] Remove unneeded protection from BiDi Connection constructor - #17067

Merged
asolntsev merged 2 commits into
SeleniumHQ:trunkfrom
asolntsev:cleanup/unneeded-code-in-bidi-connection
Feb 9, 2026
Merged

asolntsev merged 2 commits into
SeleniumHQ:trunkfrom
asolntsev:cleanup/unneeded-code-in-bidi-connection

Conversation

@asolntsev

Copy link
Copy Markdown
Contributor

At this moment, underlyingSocketClosed is freshly created, and its value if always false.

This guard was rather needed in methods close() and clearListeners().

🔗 Related Issues

See #13316 and https://github.com/SeleniumHQ/selenium/pull/13333/changes

💥 What does this PR do?

Removed "if" from the place where it was always true.

Just a tiny code cleanup.
The benefit is that field Connection.socket is now final and non-nullable.

🔄 Types of changes

  • Cleanup (formatting, renaming)

At this moment, `underlyingSocketClosed` is freshly created, and its value if always `false`.

This guard was rather needed in methods `close()` and `clearListeners()`.
@asolntsev asolntsev changed the title Remove unneeded protection from BiDi Connection constructor [java] Remove unneeded protection from BiDi Connection constructor Feb 9, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Type

Bug fix


Description

  • Remove unnecessary null check in BiDi Connection constructor

  • Make socket field final and non-nullable for better safety

  • Simplify initialization logic by removing outdated guard condition

  • Improve code clarity with direct socket assignment


File Walkthrough

Relevant files
Cleanup
Connection.java
Make socket field final and remove unnecessary guard         

java/src/org/openqa/selenium/bidi/Connection.java

  • Changed socket field from non-final to final for immutability
  • Removed unnecessary if (!underlyingSocketClosed.get()) guard in
    constructor
  • Simplified socket initialization to direct assignment
  • Removed outdated comments explaining the guard condition
+2/-10   

@asolntsev asolntsev self-assigned this Feb 9, 2026
@asolntsev asolntsev added this to the 4.41.0 milestone Feb 9, 2026
@selenium-ci selenium-ci added C-java Java Bindings B-devtools Includes everything BiDi or Chrome DevTools related labels Feb 9, 2026
@qodo-code-review

qodo-code-review Bot commented Feb 9, 2026 •

Copy link
Copy Markdown
Contributor

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
🟡
🎫 #13316
🔴 Prevent BiDi connection initialization from being triggered during driver.close() /
driver.quit() when the user did not explicitly call driver.getBiDi().
Avoid ~30s shutdown delays and TimeoutException caused by BiDi connection
establishment/handshake occurring during close() / quit().
Ensure driver shutdown (close() / quit()) remains fast and does not require users to
handle avoidable exceptions in this scenario.
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

@asolntsev
asolntsev requested a review from pujagani February 9, 2026 18:26
@qodo-code-review

qodo-code-review Bot commented Feb 9, 2026 •

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Learned
best practice
Add input validation for URL

Also validate that url is non-blank (and ideally well-formed) before opening the
socket to prevent confusing runtime failures when an empty/whitespace URL is
passed.

java/src/org/openqa/selenium/bidi/Connection.java [79-85]

 public Connection(HttpClient client, String url) {
   Require.nonNull("HTTP client", client);
   Require.nonNull("URL to connect to", url);
 
+  String trimmedUrl = url.trim();
+  if (trimmedUrl.isEmpty()) {
+    throw new IllegalArgumentException("URL to connect to must be non-blank");
+  }
+
   this.client = client;
-  this.socket = this.client.openSocket(new HttpRequest(GET, url), new Listener());
+  this.socket = this.client.openSocket(new HttpRequest(GET, trimmedUrl), new Listener());
 }
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why:
Relevant best practice - Validate/sanitize required inputs (not just non-null) and fail fast with a clear error before using them.

Low
  • Update

They can contain null values, e.g. in `SetScreenOrientationOverrideParameters`.
@asolntsev
asolntsev merged commit 06e5821 into SeleniumHQ:trunk Feb 9, 2026
78 of 79 checks passed
@asolntsev
asolntsev deleted the cleanup/unneeded-code-in-bidi-connection branch February 9, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants