File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed
src/main/java/engineering/swat/watch/impl/jdk Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -178,17 +178,20 @@ public void handleEvent(WatchEvent event) {
178178 @ Override
179179 public synchronized void close () throws IOException {
180180 IOException firstFail = null ;
181+
182+ var internalOpen = true ;
181183 var children = childWatches .keySet ().iterator ();
182- while ( true ) {
184+ do {
183185 try {
184- // First, close all child watches
185- if (children .hasNext ()) {
186- closeChildWatch (children .next ());
186+ // First, close the internal watch to prevent new child watches
187+ // from being opened concurrently while this method is running.
188+ if (internalOpen ) {
189+ internal .close ();
190+ internalOpen = false ;
187191 }
188- // Last , close the internal watch
192+ // Next , close all child watches
189193 else {
190- internal .close ();
191- break ;
194+ closeChildWatch (children .next ());
192195 }
193196 } catch (IOException ex ) {
194197 logger .error ("Could not close watch" , ex );
@@ -197,7 +200,8 @@ public synchronized void close() throws IOException {
197200 logger .error ("Could not close watch" , ex );
198201 firstFail = firstFail == null ? new IOException ("Unexpected exception when closing" , ex ) : firstFail ;
199202 }
200- }
203+ } while (children .hasNext ());
204+
201205 if (firstFail != null ) {
202206 throw firstFail ;
203207 }
You can’t perform that action at this time.
0 commit comments