3434import org .apache .logging .log4j .LogManager ;
3535import org .apache .logging .log4j .Logger ;
3636import org .checkerframework .checker .nullness .qual .MonotonicNonNull ;
37+ import org .checkerframework .checker .nullness .qual .Nullable ;
3738
3839import engineering .swat .watch .WatchEvent ;
3940
@@ -51,17 +52,17 @@ public class JDKFileWatch extends JDKBaseWatch {
5152 public JDKFileWatch (Path file , Executor exec , Consumer <WatchEvent > eventHandler ) {
5253 super (file , exec , eventHandler );
5354
54- // Use local variables to check null before field assignments (Checker
55- // Framework doesn't like it the other way around)
56- var parent = path .getParent ();
57- var fileName = path .getFileName ();
58- if (parent == null || fileName == null ) {
59- throw new IllegalArgumentException ("The root path is not a valid path for a file watch" );
60- }
55+ var message = "The root path is not a valid path for a file watch" ;
56+ this .parent = requireNonNull (path .getParent (), message );
57+ this .fileName = requireNonNull (path .getFileName (), message );
6158 assert !parent .equals (path );
59+ }
6260
63- this .parent = parent ;
64- this .fileName = fileName ;
61+ private static Path requireNonNull (@ Nullable Path p , String message ) {
62+ if (p == null ) {
63+ throw new IllegalArgumentException (message );
64+ }
65+ return p ;
6566 }
6667
6768 private void filter (WatchEvent event ) {
0 commit comments