Closed iampopovich closed 3 months ago
⏱️ Estimated effort to review [1-5] | 2, because the changes are straightforward, mostly involving syntax improvements and method updates across several files. The PR is well-organized and the changes are consistent, making it relatively easy to review. |
🧪 Relevant tests | Yes |
⚡ Possible issues | Possible Bug: The change in `PrintOptions.java` from a manual array copy to `System.arraycopy` might introduce an off-by-one error. The original code seems to have an incorrect loop condition (`i < ranges.length` should be `i < ranges.length + 1`), and the new code might not correctly handle all entries if not adjusted properly. |
🔒 Security concerns | No |
Category | Suggestion | Score |
Readability |
Simplify the condition to improve clarity___ **The conditionranges.length - 1 >= 0 is always true if ranges.length is non-negative. Consider simplifying the condition to ranges.length > 0 for clarity.**
[java/src/org/openqa/selenium/print/PrintOptions.java [70]](https://github.com/SeleniumHQ/selenium/pull/14054/files#diff-8b6352fe3693861c620fbe50178f01456b689e913b164d0ff4b788cce7c67414R70-R70)
```diff
-if (ranges.length - 1 >= 0)
+if (ranges.length > 0)
```
Suggestion importance[1-10]: 7Why: The suggestion correctly identifies a simplification in the condition check. Changing `ranges.length - 1 >= 0` to `ranges.length > 0` improves readability and understanding of the condition. | 7 |
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 58.72%. Comparing base (
57f8398
) to head (1181d73
). Report is 528 commits behind head on trunk.:exclamation: Current head 1181d73 differs from pull request most recent head 0dd4c1e
Please upload reports for the commit 0dd4c1e to get more accurate results.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Looks like the event firing decorator tests are failing. Can you investigate?
Based on the trace of the failed tests, I suspect that the requireNonNull
check is breaking the test.
System.arraycopy(Objects.requireNonNull(args), 0, args2, 1, argsLength);
The original code did not include a check that args
could be null. I will try removing the null check, and if the test continues to fail, I will revert the changes back to the original code.
In the code segment that led to the test failure, there is a tricky mechanism for handling the situation where args == null
int argsLength = args != null ? args.length : 0;
Object[] args2 = new Object[argsLength + 1];
args2[0] = target.getOriginal();
for (int i = 0; i < argsLength; i++) {
args2[i + 1] = args[i];
}
if args is null, the args2 array is created with a size sufficient only to store target.getOriginal(). Since argsLength will be zero, the for loop will not be executed, and there will be no errors in accessing the elements of args. I replaced it witharraycopy()
and explicit check if(args != null)
if(args != null) System.arraycopy(args, 0, args2, 1, argsLength);
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.
changes have been made to improve performance in various parts of the code.
Description
These changes help optimize the code and make it more efficient. I also replaced some deprecated method invocations
Motivation and Context
Types of changes
Checklist
PR Type
Enhancement, Tests
Description
isEmpty()
in multiple classes for better readability and performance.System.arraycopy()
instead of manual array copying inPrintOptions
andEventFiringDecorator
.String.format
calls withprintf
inCompletionCommand
.setScriptTimeout
withscriptTimeout
in various test files.Arrays.asList
withList.of
for immutable list creation in test files.ChromiumOptions
by using constructor initialization.RemoteLogs
by usingaddAll
.Changes walkthrough 📝
10 files
Cookie.java
Optimize empty string checks in `Cookie` class.
java/src/org/openqa/selenium/Cookie.java - Replaced empty string checks with `isEmpty()`.
ChromiumOptions.java
Simplify map initialization in `ChromiumOptions`.
java/src/org/openqa/selenium/chromium/ChromiumOptions.java - Replaced manual map population with constructor initialization.
FileExtension.java
Optimize empty string checks in `FileExtension` class.
java/src/org/openqa/selenium/firefox/FileExtension.java - Replaced empty string checks with `isEmpty()`.
CompletionCommand.java
Use `printf` instead of `String.format` in `CompletionCommand`.
java/src/org/openqa/selenium/grid/commands/CompletionCommand.java - Replaced `String.format` calls with `printf`.
ConcatenatingConfig.java
Optimize empty string checks in `ConcatenatingConfig` class.
java/src/org/openqa/selenium/grid/config/ConcatenatingConfig.java - Replaced empty string checks with `isEmpty()`.
LogLevelMapping.java
Optimize empty string checks in `LogLevelMapping` class.
java/src/org/openqa/selenium/logging/LogLevelMapping.java - Replaced empty string checks with `isEmpty()`.
PrintOptions.java
Use `System.arraycopy` in `PrintOptions`.
java/src/org/openqa/selenium/print/PrintOptions.java - Replaced manual array copy with `System.arraycopy`.
RemoteLogs.java
Simplify list addition in `RemoteLogs`.
java/src/org/openqa/selenium/remote/RemoteLogs.java - Replaced manual list addition with `addAll`.
EventFiringDecorator.java
Use `System.arraycopy` in `EventFiringDecorator`.
java/src/org/openqa/selenium/support/events/EventFiringDecorator.java - Replaced manual array copy with `System.arraycopy`.
BazelBuild.java
Optimize empty string checks in `BazelBuild` class.
java/test/org/openqa/selenium/build/BazelBuild.java - Replaced empty string checks with `isEmpty()`.
5 files
ExecutingAsyncJavascriptTest.java
Update deprecated methods and optimize list creation in tests.
java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java
setScriptTimeout
withscriptTimeout
.Arrays.asList
withList.of
.ExecutingJavascriptTest.java
Optimize list creation in `ExecutingJavascriptTest`.
java/test/org/openqa/selenium/ExecutingJavascriptTest.java - Replaced `Arrays.asList` with `List.of`.
SessionQueueGridWithTimeoutTest.java
Optimize list creation in `SessionQueueGridWithTimeoutTest`.
java/test/org/openqa/selenium/grid/router/SessionQueueGridWithTimeoutTest.java - Replaced `Arrays.asList` with `List.of`.
InternetExplorerDriverTest.java
Optimize empty string checks in `InternetExplorerDriverTest`.
java/test/org/openqa/selenium/ie/InternetExplorerDriverTest.java - Replaced empty string checks with `isEmpty()`.
RemoteWebDriverUnitTest.java
Update deprecated methods in `RemoteWebDriverUnitTest`.
java/test/org/openqa/selenium/remote/RemoteWebDriverUnitTest.java - Replaced deprecated `setScriptTimeout` with `scriptTimeout`.