You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Possible Bug: The refactoring in LocalDistributor.java uses map and orElse which might not be equivalent to the original logic if getNodeId() can return null and is expected to be handled.
Code Improvement: In DockerOptions.java, the change from index-based loop to enhanced for-loop is good for readability but ensure that the logic inside the loop does not depend on the index.
Code Cleanup: The changes in Urls.java, FormEncodedData.java, and various test files to use StandardCharsets.UTF_8 instead of "UTF-8" string are good for type safety and avoiding unnecessary exceptions.
Simplify the for-loop by removing unnecessary variable assignments
Use the enhanced for-loop directly on the devices list without intermediate variable assignment for trimming, to simplify the loop and reduce redundancy.
-String decoded = URLDecoder.decode(filters, StandardCharsets.UTF_8);-Map<String, Object> raw = new Json().toType(decoded, MAP_TYPE);+Map<String, Object> raw = new Json().toType(URLDecoder.decode(filters, StandardCharsets.UTF_8), MAP_TYPE);
Apply this suggestion
Suggestion importance[1-10]: 7
Why: Inlining the variable reduces the number of lines and simplifies the code, making it more concise without losing clarity.
7
Enhancement
Improve readability and explicit handling of optional values
Consider using Optional.ifPresentOrElse to handle the optional value more explicitly instead of map().orElse(). This can make the code more readable by clearly separating the actions for present and absent cases.
Why: The suggestion improves readability and explicitly handles the optional value, making the code more maintainable. However, the current implementation is also correct and clear.
7
Best practice
Use static import for UTF_8 to clean up the code
Since StandardCharsets.UTF_8 is a constant, you can import it statically to make the code cleaner.
)
* made the use of UTF8 encoding consistent throughout
* replaced for loop with enchanced for in DockerOptions
* removed unnecessary unboxing in test noErrorNoCry
* applied format.sh
---------
Co-authored-by: Diego Molina <[email protected]>
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Motivation and Context
These changes improve code readability, maintainability, and performance.
Types of changes
Checklist
PR Type
Enhancement, Bug fix
Description
UnsupportedEncodingException
handling withStandardCharsets.UTF_8
.LocalDistributor
usingOptional.map
.DockerOptions
.noErrorNoCry
test.Changes walkthrough 📝
8 files
LocalDistributor.java
Simplified node retrieval logic with Optional.map
java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java
Optional.map
.DockerOptions.java
Replaced traditional for loop with enhanced for-each loop
java/src/org/openqa/selenium/grid/node/docker/DockerOptions.java
Urls.java
Use StandardCharsets.UTF_8 for URL encoding
java/src/org/openqa/selenium/net/Urls.java
UnsupportedEncodingException
handling withStandardCharsets.UTF_8
.FormEncodedData.java
Use StandardCharsets.UTF_8 for URL decoding
java/src/org/openqa/selenium/remote/http/FormEncodedData.java
StandardCharsets.UTF_8
in URL decoding.ReferrerTest.java
Simplified URL encoding in tests
java/test/org/openqa/selenium/ReferrerTest.java
UnsupportedEncodingException
handling.
ListImagesTest.java
Use StandardCharsets.UTF_8 for URL decoding in tests
java/test/org/openqa/selenium/docker/v1_41/ListImagesTest.java
UnsupportedEncodingException
handling withStandardCharsets.UTF_8
.MainTest.java
Simplified PrintStream creation in tests
java/test/org/openqa/selenium/grid/MainTest.java
PrintStream
creation by removingUnsupportedEncodingException
handling.FormEncodedDataTest.java
Simplified URL encoding in tests
java/test/org/openqa/selenium/remote/http/FormEncodedDataTest.java
UnsupportedEncodingException
handling.
1 files
W3CHttpResponseCodecTest.java
Removed unnecessary unboxing in test assertions
java/test/org/openqa/selenium/remote/codec/w3c/W3CHttpResponseCodecTest.java