Skip to content

Conversation

zodac
Copy link
Contributor

@zodac zodac commented Mar 27, 2025

User description

Motivation and Context

There was some left-over Collector logic that was required in Java 8 to create an unmodifiable Map/Set. Since the minimum Java version has been upgraded to Java 11, we can replace these calls with Collectors#toUnmodifiableMap() and Collectors#toUnmodifiableSet() in the standard library (available since Java 10).

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)
  • Refactoring (no changes to public API)

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. (tested with bazel test //java/... --test_size_filters=small)

PR Type

Enhancement


Description

  • Replaced custom collectors with standard Java 10 collectors.

  • Removed redundant methods for unmodifiable collections.

  • Simplified stream operations using Collectors.toUnmodifiableMap and Collectors.toUnmodifiableSet.


Changes walkthrough 📝

Relevant files
Enhancement
PersistentCapabilities.java
Refactored to use Java 10 collectors for unmodifiable collections

java/src/org/openqa/selenium/PersistentCapabilities.java

  • Replaced toUnmodifiableMap with Collectors.toUnmodifiableMap.
  • Replaced toUnmodifiableSet with Collectors.toUnmodifiableSet.
  • Removed custom collector methods for unmodifiable collections.
  • Simplified stream operations for map and set creation.
  • +2/-16   

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ No major issues detected

    Copy link
    Contributor

    qodo-merge-pro bot commented Mar 27, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Java version compatibility issue

    Add a check for Java version compatibility. The Collectors.toUnmodifiableMap and
    Collectors.toUnmodifiableSet methods were introduced in Java 10, but the comment
    removed from the code suggests the project targets Java 8 as minimum version.

    java/src/org/openqa/selenium/PersistentCapabilities.java [20-25]

     import java.util.Map;
     import java.util.Set;
     import java.util.function.Function;
     import java.util.stream.Collectors;
     import java.util.stream.Stream;
     import org.openqa.selenium.internal.Require;
     
    +// Ensure your runtime environment is Java 10+ as Collectors.toUnmodifiableMap
    +// and Collectors.toUnmodifiableSet were introduced in Java 10
    +
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    __

    Why: This suggestion identifies a critical compatibility issue. The PR replaces custom collectors with Java 10 methods while the removed code comments explicitly stated the project targets Java 8 as minimum version. This change could break the application for users on Java 8-9 environments.

    High
    • Update

    Copy link
    Member

    @diemol diemol 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, @zodac

    @diemol diemol merged commit a23bc9f into SeleniumHQ:trunk Jul 5, 2025
    33 of 34 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.

    2 participants