3737
3838import org .apache .logging .log4j .LogManager ;
3939import org .apache .logging .log4j .Logger ;
40+ import org .checkerframework .checker .initialization .qual .NotOnlyInitialized ;
4041
4142import engineering .swat .watch .WatchEvent ;
4243import engineering .swat .watch .WatchScope ;
4546public class JDKFileTreeWatch extends JDKBaseWatch {
4647 private final Logger logger = LogManager .getLogger ();
4748 private final Map <Path , JDKFileTreeWatch > childWatches = new ConcurrentHashMap <>();
48- private final JDKBaseWatch internal ;
49+ private final @ NotOnlyInitialized JDKBaseWatch internal ;
4950
5051 public JDKFileTreeWatch (Path root , Executor exec ,
5152 BiConsumer <EventHandlingWatch , WatchEvent > eventHandler ) {
5253
5354 super (root , exec , eventHandler );
54- var internalEventHandler = updateChildWatches ().andThen (eventHandler );
55+ var internalEventHandler = new ChildWatchesUpdater ().andThen (eventHandler );
5556 this .internal = new JDKDirectoryWatch (root , exec , internalEventHandler );
5657 }
5758
5859 /**
59- * @return An event handler that updates the child watches according to the
60- * following rules: (a) when an overflow happens, it's propagated to each
61- * existing child watch; (b) when a subdirectory creation happens, a new
62- * child watch is opened for that subdirectory; (c) when a subdirectory
63- * deletion happens, an existing child watch is closed for that
64- * subdirectory.
60+ * Event handler that updates the child watches according to the following
61+ * rules: (a) when an overflow happens, it's propagated to each existing
62+ * child watch; (b) when a subdirectory creation happens, a new child watch
63+ * is opened for that subdirectory; (c) when a subdirectory deletion
64+ * happens, an existing child watch is closed for that subdirectory.
6565 */
66- private BiConsumer <EventHandlingWatch , WatchEvent > updateChildWatches () {
67- return (watch , event ) -> {
66+ private class ChildWatchesUpdater implements BiConsumer <EventHandlingWatch , WatchEvent > {
67+ @ Override
68+ public void accept (EventHandlingWatch watch , WatchEvent event ) {
6869 var kind = event .getKind ();
6970
7071 if (kind == WatchEvent .Kind .OVERFLOW ) {
71- forEachChild (this ::reportOverflowToChildWatch );
72+ forEachChild (JDKFileTreeWatch . this ::reportOverflowToChildWatch );
7273 return ;
7374 }
7475
@@ -83,11 +84,10 @@ private BiConsumer<EventHandlingWatch, WatchEvent> updateChildWatches() {
8384 // event for the watch.
8485 reportOverflowToChildWatch (child );
8586 }
86-
8787 if (kind == WatchEvent .Kind .DELETED && directory ) {
8888 closeChildWatch (child );
8989 }
90- };
90+ }
9191 }
9292
9393 private void openChildWatch (Path child ) {
0 commit comments