Skip to content
5 changes: 5 additions & 0 deletions docs/changelog/126264.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 126264
summary: '`FileWatchingService` shoudld not throw for missing file'
area: Infra/Settings
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,13 @@ public final boolean watching() {
}

private FileUpdateState readFileUpdateState(Path path) throws IOException {
BasicFileAttributes attr;
try {
attr = filesReadAttributes(path, BasicFileAttributes.class);
BasicFileAttributes attr = filesReadAttributes(path, BasicFileAttributes.class);
return new FileUpdateState(attr.lastModifiedTime().toMillis(), path.toRealPath().toString(), attr.fileKey());
Copy link
Member Author

@ywangd ywangd Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.toRealPath() can also throw NoSuchFileException and lead to failure like this one. So moving it inside the try-catch.

} catch (NoSuchFileException e) {
// file doesn't exist anymore
return null;
}

return new FileUpdateState(attr.lastModifiedTime().toMillis(), path.toRealPath().toString(), attr.fileKey());
}

// platform independent way to tell if a file changed
Expand Down
Loading