diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/service/WatchServiceImpl.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/service/WatchServiceImpl.java index b9c093d9220..c77010e37d9 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/service/WatchServiceImpl.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/service/WatchServiceImpl.java @@ -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 @@ -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()) { @@ -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