3434import java .util .concurrent .Executor ;
3535import java .util .function .BiConsumer ;
3636import java .util .function .Consumer ;
37+ import java .util .function .Function ;
3738
3839import org .apache .logging .log4j .LogManager ;
3940import org .apache .logging .log4j .Logger ;
@@ -91,7 +92,7 @@ public void accept(EventHandlingWatch watch, WatchEvent event) {
9192 }
9293
9394 private void openChildWatch (Path child ) {
94- var childWatch = new JDKFileTreeWatch (child , exec , (w , e ) ->
95+ Function < Path , JDKFileTreeWatch > newChildWatch = p -> new JDKFileTreeWatch (child , exec , (w , e ) ->
9596 // Same as `eventHandler`, except each event is pre-processed such
9697 // that the last segment of the root path becomes the first segment
9798 // of the relative path. For instance, `foo/bar` (root path) and
@@ -102,7 +103,8 @@ private void openChildWatch(Path child) {
102103 eventHandler .accept (w , relativize (e ))
103104 );
104105
105- if (childWatches .putIfAbsent (child , childWatch ) == null ) {
106+ var childWatch = childWatches .computeIfAbsent (child , newChildWatch );
107+ if (childWatch != null ) {
106108 try {
107109 childWatch .open ();
108110 } catch (IOException e ) {
0 commit comments