diff --git a/core/deployment/src/main/java/io/quarkus/deployment/util/FSWatchUtil.java b/core/deployment/src/main/java/io/quarkus/deployment/util/FSWatchUtil.java index bdc19c123e5b58..8caec740b02dcd 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/util/FSWatchUtil.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/util/FSWatchUtil.java @@ -52,20 +52,25 @@ private void doObserve(Collection watchers, long intervalMs) { for (Watcher watcher : watchers) { try { Path rootPath = watcher.rootPath; - List matchingPaths = Files.walk(rootPath) - .filter(path -> hasExtension(path, watcher.fileExtension)) - .collect(Collectors.toList()); - List changedFiles = new ArrayList<>(); - for (Path path : matchingPaths) { - long lastModifiedTime = Files.getLastModifiedTime(path).toMillis(); - if (lastModifiedTime > lastModified.computeIfAbsent(path, whatever -> 0L)) { - changedFiles.add(path); - lastModified.put(path, lastModifiedTime); - } + if (!rootPath.toFile().isDirectory()) { + // Skip directory - it does not exist. + continue; } - if (!firstRun && !changedFiles.isEmpty()) { - watcher.action.accept(changedFiles); + try (var walker = Files.walk(rootPath)) { + List matchingPaths = walker.filter(path -> hasExtension(path, watcher.fileExtension)) + .collect(Collectors.toList()); + List changedFiles = new ArrayList<>(); + for (Path path : matchingPaths) { + long lastModifiedTime = Files.getLastModifiedTime(path).toMillis(); + if (lastModifiedTime > lastModified.computeIfAbsent(path, whatever -> 0L)) { + changedFiles.add(path); + lastModified.put(path, lastModifiedTime); + } + } + if (!firstRun && !changedFiles.isEmpty()) { + watcher.action.accept(changedFiles); + } } } catch (IOException e) { log.debug("Failed checking for code gen source modifications", e);