# HG changeset patch # User igerasim # Date 1399441420 -14400 # Node ID 01f67b31eeb06fb3194982c4518218bd36958e7c # Parent 8f72d612419b3ec5bce27c37d3d7a63c2d217347 8011537: (fs) Path.register(..) clears interrupt status of thread with no InterruptedException Reviewed-by: alanb diff -r 8f72d612419b -r 01f67b31eeb0 src/share/classes/sun/nio/fs/AbstractPoller.java --- a/src/share/classes/sun/nio/fs/AbstractPoller.java Mon May 26 19:59:28 2014 +0400 +++ b/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; } } diff -r 8f72d612419b -r 01f67b31eeb0 test/java/nio/file/WatchService/Basic.java --- a/test/java/nio/file/WatchService/Basic.java Mon May 26 19:59:28 2014 +0400 +++ b/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);