!7 import java.nio.file.*; import static java.nio.file.StandardWatchEventKinds.*; p { File dir = programDir(); deleteAllProgramFiles(); makeProgramDir(); final Path path = dir.toPath(); final WatchService watchService = FileSystems.getDefault().newWatchService(); final WatchKey watchKey = path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY, OVERFLOW); thread { sleepSeconds(2); saveProgramTextFile("bla", "1"); sleepSeconds(1); //watchKey.cancel(); watchService.close(); } final new Set changes; final Countdown countdown = fiveSeconds(); print("Waiting"); expectException(ClosedWatchServiceException.class, r { while (!countdown.done()) { final WatchKey wk = watchService.take(); print("Key taken"); for (WatchEvent event : wk.pollEvents()) pcall { final Path changed = (Path) event.context(); print("Changed: " + changed + ", " + event.kind()); changes.add(changed.toFile().getName()); } bool valid = wk.reset(); if (!valid) print("Key has been unregistered"); } }); //watchService.close(); bool ok = eq(changes, lithashset("bla", "bla_temp")); print("Self-Test: " + ok); }