RFR: 8272964: java/nio/file/Files/InterruptCopy.java fails with java.lang.RuntimeException: Copy was not interrupted
Mark Sheppard
msheppar at openjdk.java.net
Thu Aug 26 19:27:24 UTC 2021
On Wed, 25 Aug 2021 23:37:50 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
> In the interrupt case, if the copy does not throw an `IOException`, rather than using the copy duration versus a threshold as the criterion for failure, instead check whether the target file does **not** exist, and if it does not, then make the test fail as this would indicate that the copy was in fact interrupted but did not throw an exception in response.
the solution looks hunky dory, but one question on the call flow in Unix for Files.copy: For the interruptible scenario, an auxiliary thread is used by Cancellable to process the copy. If the "main" thread associated with the Files.copy has yet to reach a call on the actual copy thread t.join when it is interrupted or the interrupt is delivered, then it looks like the interrupt will be missed and the InterruptExcpetion won't be generated. So is there a case for checking the interrupt status of the current thread, in the copy call flow, prior to invoking Cancellable.runInterruptibly, or before t.start for executing the actual copy or before t.join in the runInterruptibly method ? as such increasing the possibility of intercepting the Thread::interrupt in the test?
So in the call flow if the current thread's interrupt status equals interrupted prior to invoking Cancellable.runInterruptibly then throw an IOException at that point, and additionally test the interrupt status prior to invoking t.start and t.join in runInterruptibly.
The point I'm attempting to make is that the t.join in runInterruptibly is the juncture at which an interrupt can be caught, and prior to that, if I understand Thread::interrupt correctly, only the interrupt status will be set.
As such, is the test failure not also alluding a potential flaw in the interruptibility of the File.copy? That there is the possibility of an interrupt being delivered prior to the actual invocation of the "real copy" ?
-------------
PR: https://git.openjdk.java.net/jdk/pull/5260
More information about the nio-dev
mailing list