LANG-1817: UncheckedFutureImpl clears thread interrupt status when wrapping InterruptedException#1590
LANG-1817: UncheckedFutureImpl clears thread interrupt status when wrapping InterruptedException#1590inponomarev wants to merge 1 commit intoapache:masterfrom
Conversation
restore interruption status of the thread
garydgregory
left a comment
There was a problem hiding this comment.
Hello @inponomarev
Thank you for the PR.
There are a few places where we catch InterrupterdException, so we should be consistent on how this is handled. I also wonder if we should // comment each time to clarify each use case:
ThreadUtils.sleepQuietly(Duration)BackgroundInitializer.get()BackgroundInitializer.isInitialized()UncheckedFutureImpl.get()UncheckedFutureImpl.get(long, TimeUnit)
WDYT?
|
Thank you for the review and for pointing out the other places where My view here is aligned with the Brian Goetz "Java Concurrency in Practice" book: swallowing For the cases you mentioned:
If you’d like, I’m happy to extend this PR and harmonise all of these cases so they follow the same pattern. |
|
Hello @inponomarev Yes, a consistent approach throughout would be good IMO. And not just in Apache Commons Lang, but in all of Commons, so let's start here. This is an easily overlooked and obviously poorly or incorrectly tested code path. TY! FWIW, one item Commons Components (Lang, IO, and maybe others) have been vague about is whether their "quiet" semantics apply only to checked or both checked and unchecked exceptions. I should add that for now, the quiet methods should remain so (not throw), or this will likely break apps that close a bunch of resources in consecutive calls. Restoring the interrupt flag should obviously be done though. |
|
Hello @inponomarev |
|
OK please give me a couple of days for this one, probably I have to re-write the tests for deterministic behaviour meanwhile could you have a look at #1587 -- I fixed your review comments, this one should be easier Thanks for your fast replies! |
Problem
UncheckedFutureImpl.get()andget(long, TimeUnit)catchInterruptedExceptionand rethrow it asUncheckedInterruptedException, but do not restore the thread’s interrupt status.Catching
InterruptedExceptionclears the interrupt flag. As a result, callers relying onThread.currentThread().isInterrupted()could incorrectly observe a non-interrupted state after callingUncheckedFuture.get(), breaking standard cooperative cancellation patterns.This issue is tracked as LANG-1817
.
Changes
Changes
Restore the interrupt status before rethrowing UncheckedInterruptedException:
This is applied to both
get()overloads.Added regression tests that:
UncheckedFuture.get()andget(timeout, unit)on a worker thread,ExecutorService.shutdownNow(),