# HG changeset patch # User igerasim # Date 1399467040 -14400 # Node ID 39430f3393505722e0c41bd9dd50f2c2db9cbe03 # Parent 01f67b31eeb06fb3194982c4518218bd36958e7c 8042470: (fs) Path.register doesn't throw IllegalArgumentException if multiple OVERFLOW events are specified Reviewed-by: alanb, chegar diff -r 01f67b31eeb0 -r 39430f339350 src/share/classes/sun/nio/fs/AbstractPoller.java --- a/src/share/classes/sun/nio/fs/AbstractPoller.java Wed May 07 09:43:40 2014 +0400 +++ b/src/share/classes/sun/nio/fs/AbstractPoller.java Wed May 07 16:50:40 2014 +0400 @@ -100,8 +100,6 @@ // validate arguments before request to poller if (dir == null) throw new NullPointerException(); - if (events.length == 0) - throw new IllegalArgumentException("No events to register"); Set> eventSet = new HashSet<>(events.length); for (WatchEvent.Kind event: events) { // standard events @@ -114,17 +112,16 @@ } // OVERFLOW is ignored - if (event == StandardWatchEventKinds.OVERFLOW) { - if (events.length == 1) - throw new IllegalArgumentException("No events to register"); + if (event == StandardWatchEventKinds.OVERFLOW) continue; - } // null/unsupported if (event == null) throw new NullPointerException("An element in event set is 'null'"); throw new UnsupportedOperationException(event.name()); } + if (eventSet.isEmpty()) + throw new IllegalArgumentException("No events to register"); return (WatchKey)invoke(RequestType.REGISTER, dir, eventSet, modifiers); } diff -r 01f67b31eeb0 -r 39430f339350 test/java/nio/file/WatchService/Basic.java --- a/test/java/nio/file/WatchService/Basic.java Wed May 07 09:43:40 2014 +0400 +++ b/test/java/nio/file/WatchService/Basic.java Wed May 07 16:50:40 2014 +0400 @@ -22,7 +22,7 @@ */ /* @test - * @bug 4313887 6838333 7017446 8011537 + * @bug 4313887 6838333 7017446 8011537 8042470 * @summary Unit test for java.nio.file.WatchService * @library .. * @run main Basic @@ -295,24 +295,31 @@ // IllegalArgumentException System.out.println("IllegalArgumentException tests..."); try { - dir.register(watcher, new WatchEvent.Kind[]{ } ); + dir.register(watcher /*empty event list*/); throw new RuntimeException("IllegalArgumentException not thrown"); } catch (IllegalArgumentException x) { } try { // OVERFLOW is ignored so this is equivalent to the empty set - dir.register(watcher, new WatchEvent.Kind[]{ OVERFLOW }); + dir.register(watcher, OVERFLOW); + throw new RuntimeException("IllegalArgumentException not thrown"); + } catch (IllegalArgumentException x) { + } + try { + // OVERFLOW is ignored even if specified multiple times + dir.register(watcher, OVERFLOW, OVERFLOW); throw new RuntimeException("IllegalArgumentException not thrown"); } catch (IllegalArgumentException x) { } // UnsupportedOperationException try { - dir.register(watcher, new WatchEvent.Kind[]{ + dir.register(watcher, new WatchEvent.Kind() { @Override public String name() { return "custom"; } @Override public Class type() { return Object.class; } - }}); + }); + throw new RuntimeException("UnsupportedOperationException not thrown"); } catch (UnsupportedOperationException x) { } try { @@ -328,7 +335,7 @@ // NullPointerException System.out.println("NullPointerException tests..."); try { - dir.register(null, new WatchEvent.Kind[]{ ENTRY_CREATE }); + dir.register(null, ENTRY_CREATE); throw new RuntimeException("NullPointerException not thrown"); } catch (NullPointerException x) { } @@ -380,7 +387,7 @@ try { dir.register(watcher, new WatchEvent.Kind[]{ ENTRY_CREATE }); - throw new RuntimeException("ClosedWatchServiceException not thrown"); + throw new RuntimeException("ClosedWatchServiceException not thrown"); } catch (ClosedWatchServiceException x) { }