From Alan.Bateman at Sun.COM Tue Mar 2 05:06:17 2010 From: Alan.Bateman at Sun.COM (Alan Bateman) Date: Tue, 02 Mar 2010 13:06:17 +0000 Subject: Need reviewer for 6931216: TEST_BUG: test/java/nio/file/WatchService/LotsOfEvents.java failed with NPE Message-ID: <4B8D0D49.4020902@sun.com> 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> 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 modified = new HashSet(); 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 { From Christopher.Hegarty at Sun.COM Tue Mar 2 08:20:03 2010 From: Christopher.Hegarty at Sun.COM (Christopher Hegarty - Sun Microsystems) Date: Tue, 02 Mar 2010 16:20:03 +0000 Subject: Need reviewer for 6931216: TEST_BUG: test/java/nio/file/WatchService/LotsOfEvents.java failed with NPE In-Reply-To: <4B8D0D49.4020902@sun.com> References: <4B8D0D49.4020902@sun.com> Message-ID: <4B8D3AB3.7030702@sun.com> 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> 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 modified = new HashSet(); > 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 { > From Alan.Bateman at Sun.COM Tue Mar 2 08:36:04 2010 From: Alan.Bateman at Sun.COM (Alan Bateman) Date: Tue, 02 Mar 2010 16:36:04 +0000 Subject: Need reviewer for 6931216: TEST_BUG: test/java/nio/file/WatchService/LotsOfEvents.java failed with NPE In-Reply-To: <4B8D3AB3.7030702@sun.com> References: <4B8D0D49.4020902@sun.com> <4B8D3AB3.7030702@sun.com> Message-ID: <4B8D3E74.5090701@sun.com> Christopher Hegarty - Sun Microsystems wrote: > 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. That's right and I should have mentioned it - I only changed drainAndCheckOverflowEvents to keep it consistent. Thanks for reviewing. -Alan.