RFR: 8272964: java/nio/file/Files/InterruptCopy.java fails with java.lang.RuntimeException: Copy was not interrupted
Brian Burkhalter
bpb at openjdk.java.net
Thu Aug 26 20:13:26 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.
I tested three scenarios:
1. interrupt the thread which calls `Files.copy()` prior to calling `Files.copy()`;
2. self-interrupt the thread which calls `Files.copy()` in `Cancellable` on the line **before** `t.join()`.
3. self-interrupt the thread which calls `Files.copy()` in `Cancellable` on the line **after** `t.join()`.
In the first two cases an `InterruptedException` was thrown. Therefore I don't believe that there is any need to check `isInterrupted()` to avoid missing an interrupt made before spawning the "NIO-Task" thread in which the `Cancellable` task is executed.
The third case however reveals that if the thread which calls `Files.copy()` is interrupted in `runInterruptibly()` on the line _after_ `t.join()`, then the copy succeeds and no `InterruptedException` is thrown. So there is a small window in time between `t.join()` and the return from `Files.copy()` when the interrupt wil be ignored.
-------------
PR: https://git.openjdk.java.net/jdk/pull/5260
More information about the nio-dev
mailing list