Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid null hash warning in WatchServiceImpl when possible #3691

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public void unregisterListener(WatchEventListener watchEventListener) {

@Override
public void onEvent(@Nullable DirectoryChangeEvent directoryChangeEvent) throws IOException {
logger.trace("onEvent {}", directoryChangeEvent);
if (directoryChangeEvent == null || directoryChangeEvent.isDirectory()
|| directoryChangeEvent.eventType() == DirectoryChangeEvent.EventType.OVERFLOW) {
// exit early, we are neither interested in directory events nor in OVERFLOW events
Expand All @@ -223,12 +224,6 @@ public void onEvent(@Nullable DirectoryChangeEvent directoryChangeEvent) throws

Path path = directoryChangeEvent.path();

if (directoryChangeEvent.eventType() != DirectoryChangeEvent.EventType.DELETE
&& directoryChangeEvent.hash() == null) {
logger.warn("Detected invalid event (hash must not be null for CREATE/MODIFY): {}", directoryChangeEvent);
return;
}

synchronized (scheduledEvents) {
ScheduledFuture<?> future = scheduledEvents.remove(path);
if (future != null && !future.isDone()) {
Expand Down Expand Up @@ -259,9 +254,17 @@ private void notifyListeners(Path path) {
hashCache.remove(lastElement.path());
doNotify(path, Kind.DELETE);
} else if (firstElement.eventType() == DirectoryChangeEvent.EventType.CREATE) {
if (lastElement.hash() == null) {
logger.warn("Detected invalid event (hash must not be null for CREATE/MODIFY): {}", lastElement);
return;
}
hashCache.put(lastElement.path(), lastElement.hash());
doNotify(path, Kind.CREATE);
} else {
if (lastElement.hash() == null) {
logger.warn("Detected invalid event (hash must not be null for CREATE/MODIFY): {}", lastElement);
return;
}
FileHash oldHash = hashCache.put(lastElement.path(), lastElement.hash());
if (!Objects.equals(oldHash, lastElement.hash())) {
// only notify if hashes are different, otherwise the file content did not chnge
Expand Down