From 73f3d78bf9cfaa2961fcebcefe65d8f83632ea83 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 29 May 2024 22:29:25 +0700 Subject: [PATCH 01/11] replaced empty string comparison with isEmpty() invoking --- java/src/org/openqa/selenium/Cookie.java | 4 ++-- java/src/org/openqa/selenium/firefox/FileExtension.java | 2 +- .../org/openqa/selenium/grid/config/ConcatenatingConfig.java | 2 +- java/src/org/openqa/selenium/logging/LogLevelMapping.java | 2 +- java/test/org/openqa/selenium/build/BazelBuild.java | 2 +- .../org/openqa/selenium/ie/InternetExplorerDriverTest.java | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/java/src/org/openqa/selenium/Cookie.java b/java/src/org/openqa/selenium/Cookie.java index ae9890ce25f23..275e7a468cf2c 100644 --- a/java/src/org/openqa/selenium/Cookie.java +++ b/java/src/org/openqa/selenium/Cookie.java @@ -129,7 +129,7 @@ public Cookie( String sameSite) { this.name = name; this.value = value; - this.path = path == null || "".equals(path) ? "/" : path; + this.path = path == null || path.isEmpty() ? "/" : path; this.domain = stripPort(domain); this.isSecure = isSecure; @@ -203,7 +203,7 @@ private static String stripPort(String domain) { } public void validate() { - if (name == null || "".equals(name) || value == null || path == null) { + if (name == null || name.isEmpty() || value == null || path == null) { throw new IllegalArgumentException( "Required attributes are not set or " + "any non-null attribute set to null"); } diff --git a/java/src/org/openqa/selenium/firefox/FileExtension.java b/java/src/org/openqa/selenium/firefox/FileExtension.java index 1b08ac5815111..7f7253c22df85 100644 --- a/java/src/org/openqa/selenium/firefox/FileExtension.java +++ b/java/src/org/openqa/selenium/firefox/FileExtension.java @@ -209,7 +209,7 @@ public Iterator getPrefixes(String uri) { id = idNode.getTextContent(); } - if (id == null || "".equals(id.trim())) { + if (id == null || id.trim().isEmpty()) { throw new FileNotFoundException("Cannot install extension with ID: " + id); } return id; diff --git a/java/src/org/openqa/selenium/grid/config/ConcatenatingConfig.java b/java/src/org/openqa/selenium/grid/config/ConcatenatingConfig.java index ac96748154738..8b11e2f901d5b 100644 --- a/java/src/org/openqa/selenium/grid/config/ConcatenatingConfig.java +++ b/java/src/org/openqa/selenium/grid/config/ConcatenatingConfig.java @@ -37,7 +37,7 @@ public class ConcatenatingConfig implements Config { private final Map values; public ConcatenatingConfig(String prefix, char separator, Map values) { - this.prefix = prefix == null || "".equals(prefix) ? "" : (prefix + separator); + this.prefix = prefix == null || prefix.isEmpty() ? "" : (prefix + separator); this.separator = separator; this.values = diff --git a/java/src/org/openqa/selenium/logging/LogLevelMapping.java b/java/src/org/openqa/selenium/logging/LogLevelMapping.java index 2362174c58a46..7d2291d9e9e6e 100644 --- a/java/src/org/openqa/selenium/logging/LogLevelMapping.java +++ b/java/src/org/openqa/selenium/logging/LogLevelMapping.java @@ -71,7 +71,7 @@ public static String getName(Level level) { } public static Level toLevel(String logLevelName) { - if (logLevelName == null || "".equals(logLevelName)) { + if (logLevelName == null || logLevelName.isEmpty()) { // Default the log level to info. return Level.INFO; } diff --git a/java/test/org/openqa/selenium/build/BazelBuild.java b/java/test/org/openqa/selenium/build/BazelBuild.java index 850f480e41edf..02c4d085fe1d8 100644 --- a/java/test/org/openqa/selenium/build/BazelBuild.java +++ b/java/test/org/openqa/selenium/build/BazelBuild.java @@ -54,7 +54,7 @@ public void build(String target) { return; } - if (target == null || "".equals(target)) { + if (target == null || target.isEmpty()) { throw new IllegalStateException("No targets specified"); } LOG.info("\nBuilding " + target + " ..."); diff --git a/java/test/org/openqa/selenium/ie/InternetExplorerDriverTest.java b/java/test/org/openqa/selenium/ie/InternetExplorerDriverTest.java index 632ad24c6cd38..26c9637121ba0 100644 --- a/java/test/org/openqa/selenium/ie/InternetExplorerDriverTest.java +++ b/java/test/org/openqa/selenium/ie/InternetExplorerDriverTest.java @@ -138,7 +138,7 @@ void testPersistentHoverCanBeTurnedOff() throws Exception { // Intentionally wait to make sure hover DOES NOT persist. Thread.sleep(1000); - wait.until(d -> item.getText().equals("")); + wait.until(d -> item.getText().isEmpty()); assertThat(item.getText()).isEmpty(); } From 0935a6555059eff7e7cc9e849d5920f6a4195dcc Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 29 May 2024 22:56:22 +0700 Subject: [PATCH 02/11] replaced manual array copy with System.arraycopy() --- java/src/org/openqa/selenium/print/PrintOptions.java | 5 ++--- .../selenium/support/events/EventFiringDecorator.java | 9 +++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/java/src/org/openqa/selenium/print/PrintOptions.java b/java/src/org/openqa/selenium/print/PrintOptions.java index 1cc5a8165fe77..62e9c8d4b22fb 100644 --- a/java/src/org/openqa/selenium/print/PrintOptions.java +++ b/java/src/org/openqa/selenium/print/PrintOptions.java @@ -67,9 +67,8 @@ public void setPageRanges(String firstRange, String... ranges) { this.pageRanges[0] = firstRange; - for (int i = 1; i < ranges.length; i++) { - this.pageRanges[i] = ranges[i - 1]; - } + if (ranges.length - 1 >= 0) + System.arraycopy(ranges, 0, this.pageRanges, 1, ranges.length - 1); } public void setPageRanges(List ranges) { diff --git a/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java b/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java index 0eeb60f17e7f0..f7e322cc0b511 100644 --- a/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java +++ b/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java @@ -21,6 +21,7 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.logging.Level; import java.util.logging.Logger; import org.openqa.selenium.Alert; @@ -245,9 +246,7 @@ private void fireBeforeEvents( 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]; - } + System.arraycopy(Objects.requireNonNull(args), 0, args2, 1, argsLength); Method m = findMatchingMethod(listener, methodName, args2); if (m != null) { @@ -264,9 +263,7 @@ private void fireAfterEvents( int argsLength = args != null ? args.length : 0; Object[] args2 = new Object[argsLength + 1 + (isVoid ? 0 : 1)]; args2[0] = target.getOriginal(); - for (int i = 0; i < argsLength; i++) { - args2[i + 1] = args[i]; - } + System.arraycopy(Objects.requireNonNull(args), 0, args2, 1, argsLength); if (!isVoid) { args2[args2.length - 1] = res; } From 3c8a52094078e24e271b9a244c0306776eb3a562 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 29 May 2024 23:34:43 +0700 Subject: [PATCH 03/11] replaced redundant String.format invoking with printf() --- .../grid/commands/CompletionCommand.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/java/src/org/openqa/selenium/grid/commands/CompletionCommand.java b/java/src/org/openqa/selenium/grid/commands/CompletionCommand.java index 81aa6f2cf29a4..0d8a774f0b7e5 100644 --- a/java/src/org/openqa/selenium/grid/commands/CompletionCommand.java +++ b/java/src/org/openqa/selenium/grid/commands/CompletionCommand.java @@ -126,10 +126,9 @@ private void outputZshCompletions(PrintStream out) { .sorted(Comparator.comparing(CliCommand::getName)) .forEach( cmd -> { - out.println( - String.format( - " '%s:%s'", - cmd.getName(), cmd.getDescription().replace("'", "'\\''"))); + out.printf( + " '%s:%s'%n", + cmd.getName(), cmd.getDescription().replace("'", "'\\''")); }); out.println(" )"); @@ -143,8 +142,8 @@ private void outputZshCompletions(PrintStream out) { .forEach( cmd -> { String shellName = cmd.getName().replace('-', '_'); - out.println(String.format(" (%s)", cmd.getName())); - out.println(String.format(" _selenium_%s", shellName)); + out.printf(" (%s)%n", cmd.getName()); + out.printf(" _selenium_%s%n", shellName); out.println(" ;;"); }); @@ -155,7 +154,7 @@ private void outputZshCompletions(PrintStream out) { allCommands.forEach( (cmd, options) -> { - out.println(String.format("_selenium_%s() {", cmd.getName().replace('-', '_'))); + out.printf("_selenium_%s() {%n", cmd.getName().replace('-', '_')); out.println(" args=("); options.stream() @@ -170,17 +169,16 @@ private void outputZshCompletions(PrintStream out) { } if (opt.flags().size() == 1) { - out.println( - String.format( - " '%s[%s]%s'", - opt.flags().iterator().next(), quotedDesc, getZshType(opt))); + out.printf( + " '%s[%s]%s'%n", + opt.flags().iterator().next(), quotedDesc, getZshType(opt)); } else { out.print(" '"); out.print(opt.flags.stream().collect(joining(" ", "(", ")"))); out.print("'"); out.print(opt.flags.stream().collect(joining(",", "{", "}"))); out.print("'"); - out.print(String.format("[%s]", quotedDesc)); + out.printf("[%s]", quotedDesc); out.print(getZshType(opt)); out.print("'\n"); } From 2a9537f2b02716ea9a7e18e5bb43759eb522a384 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 29 May 2024 23:58:21 +0700 Subject: [PATCH 04/11] replaced deprecated setScriptTimeout with scriptTimeout according to instruction "Use scriptTimeout(Duration)" --- .../ExecutingAsyncJavascriptTest.java | 22 +++++++++---------- .../remote/RemoteWebDriverUnitTest.java | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java b/java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java index f62cd35842cb6..3ce4d7f75e252 100644 --- a/java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java +++ b/java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java @@ -45,7 +45,7 @@ class ExecutingAsyncJavascriptTest extends JupiterTestBase { public void setUp() { assumeTrue(driver instanceof JavascriptExecutor); executor = (JavascriptExecutor) driver; - driver.manage().timeouts().setScriptTimeout(Duration.ofMillis(5000)); + driver.manage().timeouts().scriptTimeout(Duration.ofMillis(5000)); } @Test @@ -56,7 +56,7 @@ public void setUp() { public void shouldSetAndGetScriptTimeout() { Duration timeout = driver.manage().timeouts().getScriptTimeout(); assertThat(timeout).hasMillis(30000); - driver.manage().timeouts().setScriptTimeout(Duration.ofMillis(3000)); + driver.manage().timeouts().scriptTimeout(Duration.ofMillis(3000)); Duration timeout2 = driver.manage().timeouts().getScriptTimeout(); assertThat(timeout2).hasMillis(3000); } @@ -185,7 +185,7 @@ public void shouldNotTimeoutIfScriptCallsbackInsideAZeroTimeout() { @Test @NotYetImplemented(SAFARI) public void shouldTimeoutIfScriptDoesNotInvokeCallbackWithLongTimeout() { - driver.manage().timeouts().setScriptTimeout(Duration.ofMillis(500)); + driver.manage().timeouts().scriptTimeout(Duration.ofMillis(500)); driver.get(pages.ajaxyPage); assertThatExceptionOfType(ScriptTimeoutException.class) .isThrownBy( @@ -199,7 +199,7 @@ public void shouldTimeoutIfScriptDoesNotInvokeCallbackWithLongTimeout() { @Ignore(IE) public void shouldDetectPageLoadsWhileWaitingOnAnAsyncScriptAndReturnAnError() { driver.get(pages.ajaxyPage); - driver.manage().timeouts().setScriptTimeout(Duration.ofMillis(100)); + driver.manage().timeouts().scriptTimeout(Duration.ofMillis(100)); assertThatExceptionOfType(WebDriverException.class) .isThrownBy( () -> executor.executeAsyncScript("window.location = '" + pages.dynamicPage + "';")); @@ -266,7 +266,7 @@ void shouldBeAbleToExecuteAsynchronousScripts() { "There should only be 1 DIV at this point, which is used for the butter message") .isEqualTo(1); - driver.manage().timeouts().setScriptTimeout(Duration.ofSeconds(15)); + driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(15)); String text = (String) executor.executeAsyncScript( @@ -317,7 +317,7 @@ void shouldBeAbleToMakeXMLHttpRequestsAndWaitForTheResponse() { + "xhr.send('');"; // empty string to stop firefox 3 from choking driver.get(pages.ajaxyPage); - driver.manage().timeouts().setScriptTimeout(Duration.ofSeconds(3)); + driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(3)); String response = (String) executor.executeAsyncScript(script, pages.sleepingPage + "?time=2"); assertThat(response.trim()) .isEqualTo("DoneSlept for 2s"); @@ -331,7 +331,7 @@ void shouldBeAbleToMakeXMLHttpRequestsAndWaitForTheResponse() { @Ignore(value = SAFARI, reason = "Does not support alerts yet") public void throwsIfScriptTriggersAlert() { driver.get(pages.simpleTestPage); - driver.manage().timeouts().setScriptTimeout(Duration.ofMillis(5000)); + driver.manage().timeouts().scriptTimeout(Duration.ofMillis(5000)); assertThatExceptionOfType(UnhandledAlertException.class) .isThrownBy( () -> @@ -350,7 +350,7 @@ public void throwsIfScriptTriggersAlert() { @Ignore(value = SAFARI, reason = "Does not support alerts yet") public void throwsIfAlertHappensDuringScript() { driver.get(pages.slowLoadingAlertPage); - driver.manage().timeouts().setScriptTimeout(Duration.ofMillis(5000)); + driver.manage().timeouts().scriptTimeout(Duration.ofMillis(5000)); assertThatExceptionOfType(UnhandledAlertException.class) .isThrownBy(() -> executor.executeAsyncScript("setTimeout(arguments[0], 1000);")); // Shouldn't throw @@ -365,7 +365,7 @@ public void throwsIfAlertHappensDuringScript() { @Ignore(value = SAFARI, reason = "Does not support alerts yet") public void throwsIfScriptTriggersAlertWhichTimesOut() { driver.get(pages.simpleTestPage); - driver.manage().timeouts().setScriptTimeout(Duration.ofMillis(5000)); + driver.manage().timeouts().scriptTimeout(Duration.ofMillis(5000)); assertThatExceptionOfType(UnhandledAlertException.class) .isThrownBy( () -> @@ -383,7 +383,7 @@ public void throwsIfScriptTriggersAlertWhichTimesOut() { @Ignore(value = SAFARI, reason = "Does not support alerts yet") public void throwsIfAlertHappensDuringScriptWhichTimesOut() { driver.get(pages.slowLoadingAlertPage); - driver.manage().timeouts().setScriptTimeout(Duration.ofMillis(5000)); + driver.manage().timeouts().scriptTimeout(Duration.ofMillis(5000)); assertThatExceptionOfType(UnhandledAlertException.class) .isThrownBy(() -> executor.executeAsyncScript("")); // Shouldn't throw @@ -397,7 +397,7 @@ public void throwsIfAlertHappensDuringScriptWhichTimesOut() { @Ignore(FIREFOX) @Ignore(value = SAFARI, reason = "Does not support alerts yet") public void includesAlertTextInUnhandledAlertException() { - driver.manage().timeouts().setScriptTimeout(Duration.ofMillis(5000)); + driver.manage().timeouts().scriptTimeout(Duration.ofMillis(5000)); String alertText = "Look! An alert!"; assertThatExceptionOfType(UnhandledAlertException.class) .isThrownBy( diff --git a/java/test/org/openqa/selenium/remote/RemoteWebDriverUnitTest.java b/java/test/org/openqa/selenium/remote/RemoteWebDriverUnitTest.java index 4d34101e50e63..7d7302740307b 100644 --- a/java/test/org/openqa/selenium/remote/RemoteWebDriverUnitTest.java +++ b/java/test/org/openqa/selenium/remote/RemoteWebDriverUnitTest.java @@ -623,7 +623,7 @@ void canHandleGetTimeoutsCommand() { void canHandleSetScriptTimeoutCommand() { WebDriverFixture fixture = new WebDriverFixture(echoCapabilities, nullValueResponder); - fixture.driver.manage().timeouts().setScriptTimeout(Duration.ofSeconds(10)); + fixture.driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(10)); fixture.verifyCommands( new CommandPayload(DriverCommand.SET_TIMEOUT, ImmutableMap.of("script", 10000L))); From 674e764f44311e20cdb8331241e3c7073d999ae0 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 30 May 2024 16:05:27 +0700 Subject: [PATCH 05/11] replaced iterators with bulk methods inoking --- java/src/org/openqa/selenium/chromium/ChromiumOptions.java | 3 +-- java/src/org/openqa/selenium/remote/RemoteLogs.java | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/java/src/org/openqa/selenium/chromium/ChromiumOptions.java b/java/src/org/openqa/selenium/chromium/ChromiumOptions.java index 2954d67f549f0..019e8c301cc33 100644 --- a/java/src/org/openqa/selenium/chromium/ChromiumOptions.java +++ b/java/src/org/openqa/selenium/chromium/ChromiumOptions.java @@ -252,8 +252,7 @@ protected Object getExtraCapability(String capabilityName) { return null; } - Map options = new TreeMap<>(); - experimentalOptions.forEach(options::put); + Map options = new TreeMap<>(experimentalOptions); if (binary != null) { options.put("binary", binary); diff --git a/java/src/org/openqa/selenium/remote/RemoteLogs.java b/java/src/org/openqa/selenium/remote/RemoteLogs.java index 368867becc795..f175aad5041e9 100644 --- a/java/src/org/openqa/selenium/remote/RemoteLogs.java +++ b/java/src/org/openqa/selenium/remote/RemoteLogs.java @@ -106,9 +106,7 @@ public Set getAvailableLogTypes() { @SuppressWarnings("unchecked") List rawList = (List) raw; Set builder = new LinkedHashSet<>(); - for (String logType : rawList) { - builder.add(logType); - } + builder.addAll(rawList); builder.addAll(getAvailableLocalLogs()); return Set.copyOf(builder); } From 1181d7357bde7e4e939c6f798dbdf78fbeb97415 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 30 May 2024 16:09:56 +0700 Subject: [PATCH 06/11] replaced list creations with List.of() there is no need to creat mutable lists in tests to only get elements --- java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java | 2 +- java/test/org/openqa/selenium/ExecutingJavascriptTest.java | 2 +- .../selenium/grid/router/SessionQueueGridWithTimeoutTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java b/java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java index 3ce4d7f75e252..a57f090b01424 100644 --- a/java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java +++ b/java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java @@ -244,7 +244,7 @@ public void shouldCatchErrorsWithMessageAndStacktraceWhenExecutingInitialScript( t -> { Throwable rootCause = getRootCause(t); assertThat(rootCause).hasMessageContaining("errormessage"); - assertThat(Arrays.asList(rootCause.getStackTrace())) + assertThat(List.of(rootCause.getStackTrace())) .extracting(StackTraceElement::getMethodName) .contains("functionB"); }); diff --git a/java/test/org/openqa/selenium/ExecutingJavascriptTest.java b/java/test/org/openqa/selenium/ExecutingJavascriptTest.java index 0a80cdd803157..c6322980ea2b0 100644 --- a/java/test/org/openqa/selenium/ExecutingJavascriptTest.java +++ b/java/test/org/openqa/selenium/ExecutingJavascriptTest.java @@ -264,7 +264,7 @@ public void testShouldThrowAnExceptionWithMessageAndStacktraceWhenTheJavascriptI t -> { Throwable rootCause = getRootCause(t); assertThat(rootCause).hasMessageContaining("errormessage"); - assertThat(Arrays.asList(rootCause.getStackTrace())) + assertThat(List.of(rootCause.getStackTrace())) .extracting(StackTraceElement::getMethodName) .contains("functionB"); }); diff --git a/java/test/org/openqa/selenium/grid/router/SessionQueueGridWithTimeoutTest.java b/java/test/org/openqa/selenium/grid/router/SessionQueueGridWithTimeoutTest.java index 455749debff96..a6a915bfd3627 100644 --- a/java/test/org/openqa/selenium/grid/router/SessionQueueGridWithTimeoutTest.java +++ b/java/test/org/openqa/selenium/grid/router/SessionQueueGridWithTimeoutTest.java @@ -163,7 +163,7 @@ void shouldBeAbleToDeleteTimedoutSessions() { try { Callable sessionCreationTask = () -> createSession(caps); List> futureList = - fixedThreadPoolService.invokeAll(Arrays.asList(sessionCreationTask)); + fixedThreadPoolService.invokeAll(List.of(sessionCreationTask)); for (Future future : futureList) { HttpResponse httpResponse = future.get(10, SECONDS); From bae701e3299391716a7e8954c78b534988c99109 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 30 May 2024 17:29:10 +0700 Subject: [PATCH 07/11] simplifying statement according to pr recommendation --- java/src/org/openqa/selenium/print/PrintOptions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/src/org/openqa/selenium/print/PrintOptions.java b/java/src/org/openqa/selenium/print/PrintOptions.java index 62e9c8d4b22fb..6897051afcace 100644 --- a/java/src/org/openqa/selenium/print/PrintOptions.java +++ b/java/src/org/openqa/selenium/print/PrintOptions.java @@ -67,7 +67,7 @@ public void setPageRanges(String firstRange, String... ranges) { this.pageRanges[0] = firstRange; - if (ranges.length - 1 >= 0) + if (ranges.length>0) System.arraycopy(ranges, 0, this.pageRanges, 1, ranges.length - 1); } From 5cb628493b1c954a3bb16f6cc0fce84f05214603 Mon Sep 17 00:00:00 2001 From: Alex Popov Date: Thu, 30 May 2024 11:07:38 +0000 Subject: [PATCH 08/11] applying format.sh --- .../org/openqa/selenium/grid/commands/CompletionCommand.java | 5 ++--- java/src/org/openqa/selenium/print/PrintOptions.java | 3 +-- .../org/openqa/selenium/ExecutingAsyncJavascriptTest.java | 1 - .../grid/router/SessionQueueGridWithTimeoutTest.java | 1 - 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/java/src/org/openqa/selenium/grid/commands/CompletionCommand.java b/java/src/org/openqa/selenium/grid/commands/CompletionCommand.java index 0d8a774f0b7e5..5522de077ca83 100644 --- a/java/src/org/openqa/selenium/grid/commands/CompletionCommand.java +++ b/java/src/org/openqa/selenium/grid/commands/CompletionCommand.java @@ -127,8 +127,7 @@ private void outputZshCompletions(PrintStream out) { .forEach( cmd -> { out.printf( - " '%s:%s'%n", - cmd.getName(), cmd.getDescription().replace("'", "'\\''")); + " '%s:%s'%n", cmd.getName(), cmd.getDescription().replace("'", "'\\''")); }); out.println(" )"); @@ -170,7 +169,7 @@ private void outputZshCompletions(PrintStream out) { if (opt.flags().size() == 1) { out.printf( - " '%s[%s]%s'%n", + " '%s[%s]%s'%n", opt.flags().iterator().next(), quotedDesc, getZshType(opt)); } else { out.print(" '"); diff --git a/java/src/org/openqa/selenium/print/PrintOptions.java b/java/src/org/openqa/selenium/print/PrintOptions.java index 6897051afcace..16592a8bec1d3 100644 --- a/java/src/org/openqa/selenium/print/PrintOptions.java +++ b/java/src/org/openqa/selenium/print/PrintOptions.java @@ -67,8 +67,7 @@ public void setPageRanges(String firstRange, String... ranges) { this.pageRanges[0] = firstRange; - if (ranges.length>0) - System.arraycopy(ranges, 0, this.pageRanges, 1, ranges.length - 1); + if (ranges.length > 0) System.arraycopy(ranges, 0, this.pageRanges, 1, ranges.length - 1); } public void setPageRanges(List ranges) { diff --git a/java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java b/java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java index a57f090b01424..d81496aec1865 100644 --- a/java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java +++ b/java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java @@ -28,7 +28,6 @@ import static org.openqa.selenium.testing.drivers.Browser.SAFARI; import java.time.Duration; -import java.util.Arrays; import java.util.Iterator; import java.util.List; import org.junit.jupiter.api.BeforeEach; diff --git a/java/test/org/openqa/selenium/grid/router/SessionQueueGridWithTimeoutTest.java b/java/test/org/openqa/selenium/grid/router/SessionQueueGridWithTimeoutTest.java index a6a915bfd3627..9e67ccf4d1b6c 100644 --- a/java/test/org/openqa/selenium/grid/router/SessionQueueGridWithTimeoutTest.java +++ b/java/test/org/openqa/selenium/grid/router/SessionQueueGridWithTimeoutTest.java @@ -30,7 +30,6 @@ import java.net.URISyntaxException; import java.time.Duration; import java.time.Instant; -import java.util.Arrays; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; From dd989b6a14ad0849ddc32a09428137d66e30b7b4 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 5 Jun 2024 21:53:32 +0700 Subject: [PATCH 09/11] trying to fix test --- .../openqa/selenium/support/events/EventFiringDecorator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java b/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java index f7e322cc0b511..225a264c119b4 100644 --- a/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java +++ b/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java @@ -246,7 +246,7 @@ private void fireBeforeEvents( int argsLength = args != null ? args.length : 0; Object[] args2 = new Object[argsLength + 1]; args2[0] = target.getOriginal(); - System.arraycopy(Objects.requireNonNull(args), 0, args2, 1, argsLength); + System.arraycopy(args, 0, args2, 1, argsLength); Method m = findMatchingMethod(listener, methodName, args2); if (m != null) { @@ -263,7 +263,7 @@ private void fireAfterEvents( int argsLength = args != null ? args.length : 0; Object[] args2 = new Object[argsLength + 1 + (isVoid ? 0 : 1)]; args2[0] = target.getOriginal(); - System.arraycopy(Objects.requireNonNull(args), 0, args2, 1, argsLength); + System.arraycopy(args, 0, args2, 1, argsLength); if (!isVoid) { args2[args2.length - 1] = res; } From 47f4fe13ab240306ac6c90e1bba450ff914f230f Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 5 Jun 2024 22:33:02 +0700 Subject: [PATCH 10/11] handle case when args is null --- .../openqa/selenium/support/events/EventFiringDecorator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java b/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java index 225a264c119b4..ce72a8300ea6f 100644 --- a/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java +++ b/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java @@ -246,7 +246,7 @@ private void fireBeforeEvents( int argsLength = args != null ? args.length : 0; Object[] args2 = new Object[argsLength + 1]; args2[0] = target.getOriginal(); - System.arraycopy(args, 0, args2, 1, argsLength); + if(args != null) System.arraycopy(args, 0, args2, 1, argsLength); Method m = findMatchingMethod(listener, methodName, args2); if (m != null) { @@ -263,7 +263,7 @@ private void fireAfterEvents( int argsLength = args != null ? args.length : 0; Object[] args2 = new Object[argsLength + 1 + (isVoid ? 0 : 1)]; args2[0] = target.getOriginal(); - System.arraycopy(args, 0, args2, 1, argsLength); + if(args != null) System.arraycopy(Objects.requireNonNull(args), 0, args2, 1, argsLength); if (!isVoid) { args2[args2.length - 1] = res; } From 132aeadfeb5e6cb02c9cd5ad383afdcf705d9f0f Mon Sep 17 00:00:00 2001 From: Alex Popov Date: Wed, 5 Jun 2024 16:32:05 +0000 Subject: [PATCH 11/11] applying format.sh --- .../support/events/EventFiringDecorator.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java b/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java index ce72a8300ea6f..bb02186d91057 100644 --- a/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java +++ b/java/src/org/openqa/selenium/support/events/EventFiringDecorator.java @@ -246,12 +246,10 @@ private void fireBeforeEvents( int argsLength = args != null ? args.length : 0; Object[] args2 = new Object[argsLength + 1]; args2[0] = target.getOriginal(); - if(args != null) System.arraycopy(args, 0, args2, 1, argsLength); + if (args != null) System.arraycopy(args, 0, args2, 1, argsLength); Method m = findMatchingMethod(listener, methodName, args2); - if (m != null) { - callListenerMethod(m, listener, args2); - } + if (m != null) callListenerMethod(m, listener, args2); } private void fireAfterEvents( @@ -260,18 +258,15 @@ private void fireAfterEvents( boolean isVoid = method.getReturnType() == Void.TYPE || method.getReturnType() == WebDriver.Timeouts.class; + int argsLength = args != null ? args.length : 0; Object[] args2 = new Object[argsLength + 1 + (isVoid ? 0 : 1)]; args2[0] = target.getOriginal(); - if(args != null) System.arraycopy(Objects.requireNonNull(args), 0, args2, 1, argsLength); - if (!isVoid) { - args2[args2.length - 1] = res; - } + if (args != null) System.arraycopy(Objects.requireNonNull(args), 0, args2, 1, argsLength); + if (!isVoid) args2[args2.length - 1] = res; Method m = findMatchingMethod(listener, methodName, args2); - if (m != null) { - callListenerMethod(m, listener, args2); - } + if (m != null) callListenerMethod(m, listener, args2); try { if (target.getOriginal() instanceof WebDriver) {