Skip to content

Commit c365b4a

Browse files
committed
Move null preprocessing of relative path back to the constructor of WatchEvent (because having it outside didn't lead to significantly simpler code overall)
1 parent ff91702 commit c365b4a

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/main/java/engineering/swat/watch/WatchEvent.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
import java.nio.file.Path;
3030

31+
import org.checkerframework.checker.nullness.qual.Nullable;
32+
3133
/**
3234
* The library publishes these events to all subscribers, they are immutable and safe to share around.
3335
*/
@@ -67,13 +69,13 @@ public enum Kind {
6769
private final Path relativePath;
6870

6971
public WatchEvent(Kind kind, Path rootPath) {
70-
this(kind, rootPath, Path.of(""));
72+
this(kind, rootPath, null);
7173
}
7274

73-
public WatchEvent(Kind kind, Path rootPath, Path relativePath) {
75+
public WatchEvent(Kind kind, Path rootPath, @Nullable Path relativePath) {
7476
this.kind = kind;
7577
this.rootPath = rootPath;
76-
this.relativePath = relativePath;
78+
this.relativePath = relativePath == null ? Path.of("") : relativePath;
7779
}
7880

7981
public Kind getKind() {

src/main/java/engineering/swat/watch/impl/jdk/JDKBaseWatch.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,9 @@ protected boolean startIfFirstTime() throws IOException {
9090
}
9191

9292
protected WatchEvent translate(java.nio.file.WatchEvent<?> jdkEvent) {
93-
var jdkKind = jdkEvent.kind();
94-
var context = jdkKind == StandardWatchEventKinds.OVERFLOW ? null : jdkEvent.context();
95-
96-
var kind = translate(jdkKind);
93+
var kind = translate(jdkEvent.kind());
9794
var rootPath = path;
98-
var relativePath = context == null ? Path.of("") : (Path) context;
95+
var relativePath = kind == WatchEvent.Kind.OVERFLOW ? null : (@Nullable Path) jdkEvent.context();
9996

10097
var event = new WatchEvent(kind, rootPath, relativePath);
10198
logger.trace("Translated: {} to {}", jdkEvent, event);

0 commit comments

Comments
 (0)