Need reviewer for 6931216: TEST_BUG: test/java/nio/file/WatchService/LotsOfEvents.java failed with NPE
Christopher Hegarty - Sun Microsystems
Christopher.Hegarty at Sun.COM
Tue Mar 2 08:20:03 PST 2010
Looks fine.
BTW, I don't think the first part of the change is necessary since the
enclosing method is never called with count <= 0, but it is certainly
good practice and may prevent future failures if this tests evolves.
-Chris.
Alan Bateman wrote:
> One of the WatchService tests failed with a NullPointerException in one
> of Kelly's test runs. It's a test issue and the fix is trivial. The
> reason for the NPE is that the test incorrectly assumes that the first
> batch of events will be read retrieved within 15s. The fix is to
> restructure the loops so that it checks the key at the beginning rather
> than the end.
>
> Thanks,
>
> -Alan.
>
>
> diff -r 893034df4ec2 test/java/nio/file/WatchService/LotsOfEvents.java
> --- a/test/java/nio/file/WatchService/LotsOfEvents.java Mon Mar 01
> 18:00:47 2010 +0000
> +++ b/test/java/nio/file/WatchService/LotsOfEvents.java Tue Mar 02
> 12:58:07 2010 +0000
> @@ -102,7 +102,7 @@ public class LotsOfEvents {
>
> int nread = 0;
> boolean gotOverflow = false;
> - do {
> + while (key != null) {
> List<WatchEvent<?>> events = key.pollEvents();
> for (WatchEvent<?> event: events) {
> WatchEvent.Kind<?> kind = event.kind();
> @@ -122,7 +122,7 @@ public class LotsOfEvents {
> if (!key.reset())
> throw new RuntimeException("Key is no longer valid");
> key = watcher.poll(2, TimeUnit.SECONDS);
> - } while (key != null);
> + }
>
> // check that all expected events were received or there was an
> overflow
> if (nread < count && !gotOverflow)
> @@ -168,7 +168,7 @@ public class LotsOfEvents {
> // process events and ensure that we don't get repeated
> modify
> // events for the same file.
> WatchKey key = watcher.poll(15, TimeUnit.SECONDS);
> - do {
> + while (key != null) {
> Set<Path> modified = new HashSet<Path>();
> for (WatchEvent<?> event: key.pollEvents()) {
> WatchEvent.Kind<?> kind = event.kind();
> @@ -186,7 +186,7 @@ public class LotsOfEvents {
> if (!key.reset())
> throw new RuntimeException("Key is no longer
> valid");
> key = watcher.poll(2, TimeUnit.SECONDS);
> - } while (key != null);
> + }
> }
>
> } finally {
>
More information about the nio-dev
mailing list