Restore the interrupt status in UrlChecker.waitUntilUnavailable#17719
Restore the interrupt status in UrlChecker.waitUntilUnavailable#17719vasiliy-mikhailov wants to merge 1 commit into
Conversation
waitUntilUnavailable caught InterruptedException and rethrew it wrapped in a RuntimeException without re-setting the thread interrupt flag, unlike the sibling waitUntilAvailable. Re-set the flag so callers can still observe the interruption.
PR Summary by QodoRestore interrupt status in UrlChecker.waitUntilUnavailable Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
Context used✅ Compliance rules (platform):
18 rules 1. waitUntilUnavailable missing Javadoc
|
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| throw new RuntimeException(e); | ||
| } catch (ExecutionException e) { | ||
| throw new RuntimeException(e); |
There was a problem hiding this comment.
1. waituntilunavailable missing javadoc 📘 Rule violation ✧ Quality
The modified public method waitUntilUnavailable(long timeout, TimeUnit unit, URL url) has no Javadoc block, so its parameters and TimeoutException contract are undocumented. This violates the requirement for complete Javadoc on changed public API methods.
Agent Prompt
## Issue description
A changed public method `waitUntilUnavailable(...)` lacks a Javadoc block and therefore does not document purpose, `@param` tags, or the `@throws` contract.
## Issue Context
This PR modifies the behavior of `UrlChecker.waitUntilUnavailable`, so it is in-scope for the “complete Javadoc on public API methods” requirement.
## Fix Focus Areas
- java/src/org/openqa/selenium/net/UrlChecker.java[108-114]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| @Test | ||
| void waitUntilUnavailablePreservesInterruptStatus() throws Exception { | ||
| Thread caller = Thread.currentThread(); | ||
| Thread interrupter = | ||
| new Thread( | ||
| () -> { | ||
| try { | ||
| Thread.sleep(500); | ||
| } catch (InterruptedException ignored) { | ||
| } | ||
| caller.interrupt(); | ||
| }); | ||
| interrupter.start(); | ||
|
|
||
| boolean threw = false; | ||
| boolean preserved = false; | ||
| try { | ||
| urlChecker.waitUntilUnavailable(10, TimeUnit.SECONDS, url); | ||
| } catch (RuntimeException expected) { | ||
| threw = true; | ||
| preserved = Thread.currentThread().isInterrupted(); | ||
| Thread.interrupted(); | ||
| } | ||
| interrupter.join(); | ||
|
|
||
| assertThat(threw).isTrue(); | ||
| assertThat(preserved).isTrue(); | ||
| } |
There was a problem hiding this comment.
2. Interrupt test doesn’t block 🐞 Bug ≡ Correctness
waitUntilUnavailablePreservesInterruptStatus calls waitUntilUnavailable while the NettyAppServer created in @BeforeEach is never started, so waitUntilUnavailable can return immediately on IOException and never throw the expected RuntimeException. As written, the test can fail (no exception thrown) and does not reliably validate that the interrupt status is preserved during a blocking wait.
Agent Prompt
## Issue description
The new test intends to verify that interrupt status is preserved when `waitUntilUnavailable` is interrupted while blocked, but it calls `waitUntilUnavailable` when the server is not running. Because `waitUntilUnavailable` treats connection `IOException` as “unavailable” and returns immediately, the test often won’t block long enough to be interrupted and therefore won’t throw the expected `RuntimeException`.
## Issue Context
`@BeforeEach` creates `this.server` and `this.url` but does not start the server. In `UrlChecker.waitUntilUnavailable`, an `IOException` while connecting returns success immediately.
## Fix Focus Areas
- java/test/org/openqa/selenium/net/UrlCheckerTest.java[42-57]
- java/test/org/openqa/selenium/net/UrlCheckerTest.java[106-133]
- java/src/org/openqa/selenium/net/UrlChecker.java[112-163]
## Suggested fix
In `waitUntilUnavailablePreservesInterruptStatus`, start the server (and optionally call `waitUntilAvailable` to ensure it is serving HTTP 200) before invoking `waitUntilUnavailable`, and keep the server running so `waitUntilUnavailable` blocks until the interrupter interrupts the calling thread. Also ensure cleanup (joining interrupter and clearing interrupt) happens even if assertions fail (e.g., via `try/finally`).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
UrlChecker.waitUntilUnavailablecatchesInterruptedExceptionand rethrows it wrapped in aRuntimeExceptionwithout re-setting the thread's interrupt flag, so a caller can no longer tell the wait was interrupted. The siblingwaitUntilAvailablealready restores the flag in the same place, so this just makes the two consistent.The added test interrupts the calling thread while
waitUntilUnavailableis waiting and asserts the interrupt status is preserved.AI assistance disclosure
This contribution was produced with the help of an AI pipeline. The pipeline processed a large amount of source code to surface suspected bugs, reproduced a subset of them with failing unit tests and generated candidate fixes, and prepared pull requests from the ones that held up. Each PR was then reviewed and verified by a human before being opened: the fix and test were checked by hand and the test was confirmed to fail before the change and pass after.