8011537: (fs) Path.register(..) clears interrupt status of thread with no InterruptedException
Reviewed-by: alanb
--- a/jdk/src/share/classes/sun/nio/fs/AbstractPoller.java Wed May 07 02:24:01 2014 +0000
+++ b/jdk/src/share/classes/sun/nio/fs/AbstractPoller.java Wed May 07 09:43:40 2014 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -192,14 +192,17 @@
* the request.
*/
Object awaitResult() {
+ boolean interrupted = false;
synchronized (this) {
while (!completed) {
try {
wait();
} catch (InterruptedException x) {
- // ignore
+ interrupted = true;
}
}
+ if (interrupted)
+ Thread.currentThread().interrupt();
return result;
}
}
--- a/jdk/test/java/nio/file/WatchService/Basic.java Wed May 07 02:24:01 2014 +0000
+++ b/jdk/test/java/nio/file/WatchService/Basic.java Wed May 07 09:43:40 2014 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887 6838333 7017446
+ * @bug 4313887 6838333 7017446 8011537
* @summary Unit test for java.nio.file.WatchService
* @library ..
* @run main Basic
@@ -468,6 +468,28 @@
}
}
+ /**
+ * Test that thread interruped status is preserved upon a call
+ * to register()
+ */
+ static void testThreadInterrupt(Path dir) throws IOException {
+ System.out.println("-- Thread interrupted status test --");
+
+ FileSystem fs = FileSystems.getDefault();
+ Thread curr = Thread.currentThread();
+ try (WatchService watcher = fs.newWatchService()) {
+ System.out.println("interrupting current thread");
+ curr.interrupt();
+ dir.register(watcher, ENTRY_CREATE);
+ if (!curr.isInterrupted())
+ throw new RuntimeException("thread should remain interrupted");
+ System.out.println("current thread is still interrupted");
+ System.out.println("OKAY");
+ } finally {
+ curr.interrupted();
+ }
+ }
+
public static void main(String[] args) throws IOException {
Path dir = TestUtil.createTemporaryDirectory();
try {
@@ -478,6 +500,7 @@
testWakeup(dir);
testExceptions(dir);
testTwoWatchers(dir);
+ testThreadInterrupt(dir);
} finally {
TestUtil.removeAll(dir);