Open iampopovich opened 2 days ago
⏱️ Estimated effort to review [1-5] | 2 |
🧪 Relevant tests | No |
🔒 Security concerns | No |
⚡ Key issues to review |
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. |
Category | Suggestion | Score |
Maintainability |
Simplify the for-loop by removing unnecessary variable assignments___ **Use the enhanced for-loop directly on thedevices list without intermediate variable assignment for trimming, to simplify the loop and reduce redundancy.** [java/src/org/openqa/selenium/grid/node/docker/DockerOptions.java [210-211]](https://github.com/SeleniumHQ/selenium/pull/14218/files#diff-5a4e578c5c5711a9b26d92a059bfe58b426177f8d2fc68aaaa79cd0fbef456bdR210-R211) ```diff for (String device : devices) { - String deviceMappingDefined = device.trim(); + Matcher matcher = linuxDeviceMappingWithDefaultPermissionsPattern.matcher(device.trim()); ``` - [ ] **Apply this suggestion** Suggestion importance[1-10]: 8Why: This suggestion simplifies the loop and reduces redundancy, improving code readability and maintainability. | 8 |
Reduce variable usage by inlining expressions___ **Inline thedecoded variable directly into the toType method call to streamline the code and reduce the number of lines.** [java/test/org/openqa/selenium/docker/v1_41/ListImagesTest.java [44-45]](https://github.com/SeleniumHQ/selenium/pull/14218/files#diff-9d6fce0e3e1c13ec6a6ba9cad3106b8c1e03282c0ace46692dc5cc096ae6e0b3R44-R45) ```diff -String decoded = URLDecoder.decode(filters, StandardCharsets.UTF_8); -Map Suggestion importance[1-10]: 7Why: 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 usingOptional.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.** [java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java [881]](https://github.com/SeleniumHQ/selenium/pull/14218/files#diff-024d7dccb0a4ff87c444dc3549032e7c6b2595f582f4f267cdf48c7f8c2f87c1R881-R881) ```diff -return nodeStatus.map(status -> nodes.get(status.getNodeId())).orElse(null); +nodeStatus.ifPresentOrElse( + status -> return nodes.get(status.getNodeId()), + () -> return null +); ``` - [ ] **Apply this suggestion** Suggestion importance[1-10]: 7Why: 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
___
**Since | 6 |
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 - Simplified node retrieval logic using `Optional.map`.
DockerOptions.java
Replaced traditional for loop with enhanced for-each loop
java/src/org/openqa/selenium/grid/node/docker/DockerOptions.java - Replaced traditional for loop with enhanced for-each loop.
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 - Removed unnecessary unboxing in assertions.