Skip to content

Conversation

nnnnoel
Copy link
Contributor

@nnnnoel nnnnoel commented Sep 3, 2024

User description

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Merge overload's business logic to make it easy to see at a glance

Motivation and Context

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)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Enhancement


Description

  • Refactored deprecated timeout methods to delegate to their Duration-based counterparts

  • Updated NEW_SESSION(Capabilities) to call the collection-based overload

  • Eliminated duplicate business logic across method overloads


Diagram Walkthrough

flowchart LR
  A["Deprecated TimeUnit methods"] -- "delegate to" --> B["Duration-based methods"]
  C["Single Capabilities overload"] -- "delegates to" --> D["Collection-based overload"]
Loading

File Walkthrough

Relevant files
Enhancement
DriverCommand.java
Consolidate overloaded method implementations to reduce duplication

java/src/org/openqa/selenium/remote/DriverCommand.java

  • Refactored NEW_SESSION(Capabilities) to delegate to
    NEW_SESSION(Collection)
  • Updated SET_IMPLICIT_WAIT_TIMEOUT(long, TimeUnit) to call
    Duration-based overload
  • Updated SET_SCRIPT_TIMEOUT(long, TimeUnit) to call Duration-based
    overload
  • Updated SET_PAGE_LOAD_TIMEOUT(long, TimeUnit) to call Duration-based
    overload
+4/-7     

@CLAassistant
Copy link

CLAassistant commented Sep 3, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

qodo-merge-pro bot commented Sep 3, 2024

PR Reviewer Guide 🔍

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Key issues to review

Potential Regression
The removal of Require.nonNull("Capabilities", capabilities) check in the NEW_SESSION method might lead to null pointer exceptions if null capabilities are passed.

Language Level Change
The LANGUAGE_LEVEL has been changed from JDK_11 to JDK_17, which might affect compatibility with older Java versions.

Copy link
Contributor

qodo-merge-pro bot commented Sep 3, 2024

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Score
Possible issue
✅ Add a null check for the input parameter to prevent potential null pointer exceptions
Suggestion Impact:A null check for the capabilities parameter was added using Require.nonNull to prevent potential NullPointerException.

code diff:

+    Require.nonNull("Capabilities", capabilities);

Consider adding a null check for the capabilities parameter before calling
singleton() to prevent potential NullPointerException.

java/src/org/openqa/selenium/remote/DriverCommand.java [165-166]

 static CommandPayload NEW_SESSION(Capabilities capabilities) {
+  Require.nonNull("Capabilities", capabilities);
   return NEW_SESSION(singleton(capabilities));
 }
 
  • Apply this suggestion
Suggestion importance[1-10]: 9

Why: Adding a null check for the capabilities parameter is crucial to prevent potential NullPointerException, which enhances the robustness of the code.

9
Maintainability
Add a comment to explain the rationale behind a significant version upgrade

Consider adding a comment explaining the reason for upgrading the LANGUAGE_LEVEL
from JDK_11 to JDK_17, as this change might have implications for the project's
compatibility and requirements.

java/java.iml [6]

+<!-- Upgraded to JDK 17 for improved performance and new language features -->
 <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_17">
 
  • Apply this suggestion
Suggestion importance[1-10]: 7

Why: Adding a comment to explain the upgrade to JDK 17 is beneficial for maintainability, as it provides context for future developers about the project's compatibility and requirements.

7
Enhancement
Use a more readable time unit conversion method for improved code clarity

Consider using Duration.ofSeconds() instead of Duration.ofMillis() for better
readability when converting from TimeUnit to Duration.

java/src/org/openqa/selenium/remote/DriverCommand.java [347-348]

 static CommandPayload SET_IMPLICIT_WAIT_TIMEOUT(long time, TimeUnit unit) {
-  return SET_IMPLICIT_WAIT_TIMEOUT(Duration.ofMillis(unit.toMillis(time)));
+  return SET_IMPLICIT_WAIT_TIMEOUT(Duration.ofSeconds(unit.toSeconds(time)));
 }
 
  • Apply this suggestion
Suggestion importance[1-10]: 5

Why: While using Duration.ofSeconds() can improve readability, it is a minor enhancement and does not significantly impact functionality or performance.

5

@nnnnoel nnnnoel changed the title refactor(remote/command): Merge overload's business logic [java] refactor(remote/command): Merge overload's business logic Sep 3, 2024
shs96c
shs96c previously requested changes Sep 5, 2024
Copy link
Member

@shs96c shs96c left a comment

Choose a reason for hiding this comment

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

Thank you for the PR. It looks great, but please revert the change to java.iml

@nnnnoel nnnnoel force-pushed the refactor/merge-overloads branch from d8f041e to ea43ee8 Compare September 11, 2024 07:50
@nnnnoel nnnnoel requested a review from shs96c September 12, 2024 03:09
@nnnnoel
Copy link
Contributor Author

nnnnoel commented Sep 27, 2024

@shs96c I applied your review. Please can you see the submitted commit?

@nnnnoel nnnnoel force-pushed the refactor/merge-overloads branch from 8f5c37e to 49b0db5 Compare November 4, 2024 18:56
@nnnnoel
Copy link
Contributor Author

nnnnoel commented Nov 6, 2024

@shs96c Please can you provide any updates?

@VietND96 VietND96 requested review from diemol and pujagani January 3, 2025 21:53
@github-actions github-actions bot added the J-stale Applied to issues that become stale, and eventually closed. label Sep 26, 2025
@github-actions github-actions bot closed this Oct 11, 2025
@diemol diemol reopened this Oct 14, 2025
Copy link
Contributor

qodo-merge-pro bot commented Oct 14, 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
No custom compliance provided

Follow the guide to enable custom compliance check.

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

Copy link
Contributor

qodo-merge-pro bot commented Oct 14, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Learned
best practice
Guard against null elements in collection

Also validate that the collection does not contain null elements to avoid NPEs
in downstream code. Add a check and clear error message.

java/src/org/openqa/selenium/remote/DriverCommand.java [170-177]

 static CommandPayload NEW_SESSION(Collection<Capabilities> capabilities) {
   Require.nonNull("Capabilities", capabilities);
   if (capabilities.isEmpty()) {
     throw new IllegalArgumentException("Capabilities for new session must not be empty");
   }
+  if (capabilities.stream().anyMatch(c -> c == null)) {
+    throw new IllegalArgumentException("Capabilities collection must not contain null elements");
+  }
 
   return new CommandPayload(NEW_SESSION, Map.of("capabilities", capabilities));
 }
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why:
Relevant best practice - Validate inputs and states early to prevent NPEs and logic errors, especially for null checks on parameters to public APIs.

Low
Null-check TimeUnit in deprecated setters

Add null checks for the TimeUnit parameter (and consider negative times) to
prevent NPEs and undefined behavior.

java/src/org/openqa/selenium/remote/DriverCommand.java [347-368]

 @Deprecated
 static CommandPayload SET_IMPLICIT_WAIT_TIMEOUT(long time, TimeUnit unit) {
+  Require.nonNull("Time unit", unit);
   return SET_IMPLICIT_WAIT_TIMEOUT(Duration.ofMillis(unit.toMillis(time)));
 }
 
 @Deprecated
 static CommandPayload SET_SCRIPT_TIMEOUT(long time, TimeUnit unit) {
+  Require.nonNull("Time unit", unit);
   return SET_SCRIPT_TIMEOUT(Duration.ofMillis(unit.toMillis(time)));
 }
 
 @Deprecated
 static CommandPayload SET_PAGE_LOAD_TIMEOUT(long time, TimeUnit unit) {
+  Require.nonNull("Time unit", unit);
   return SET_PAGE_LOAD_TIMEOUT(Duration.ofMillis(unit.toMillis(time)));
 }
  • Apply / Chat
Suggestion importance[1-10]: 5

__

Why:
Relevant best practice - Validate inputs early with precise checks; ensure deprecated overloads converting time values guard against null TimeUnit.

Low
  • More

@github-actions github-actions bot removed the J-stale Applied to issues that become stale, and eventually closed. label Oct 14, 2025
@diemol diemol dismissed shs96c’s stale review October 14, 2025 12:59

The requested change was addressed.

@diemol diemol merged commit 84358bd into SeleniumHQ:trunk Oct 14, 2025
37 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants