You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2026/10/08 13:08:25 UTC
(camel) 01/01: [backport camel-4.22.x] CAMEL-25427: camel-support - on-demand route reload no longer fails after a route file is removed
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch backport/27565-to-camel-4.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 1d5d6fbf7fea49df751866c0a0dd1747d400d897
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Oct 8 13:08:09 2026 +0000
[backport camel-4.22.x] CAMEL-25427: camel-support - on-demand route reload no longer fails after a route file is removed
---
.../camel/support/RouteWatcherReloadStrategy.java | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java b/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
index 8a1d09885194..564a5c2b61cd 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
@@ -262,8 +262,8 @@ public class RouteWatcherReloadStrategy extends FileWatcherResourceReloadStrateg
// last update failed, so we need to update all previous sources to ensure we go back
// to the last working set
previousSources.forEach(rs -> {
- // remember all the sources of the current routes (except the updated)
- if (rs != null && !equalResourceLocation(resources, rs)) {
+ // remember all the sources of the current routes (except the updated, and those whose file is gone)
+ if (rs != null && !isDeletedFile(rs) && !equalResourceLocation(resources, rs)) {
sources.add(rs);
}
});
@@ -273,9 +273,11 @@ public class RouteWatcherReloadStrategy extends FileWatcherResourceReloadStrateg
// should all existing routes be stopped and removed first?
if (removeAllRoutes) {
// remember all the sources of the current routes (except the updated)
+ // (the file of a route may have been removed since it loaded: on-demand reload only passes the files
+ // that exist, so its routes are removed like those of a changed file, CAMEL-25427)
getCamelContext().getRoutes().forEach(r -> {
Resource rs = r.getSourceResource();
- if (rs != null && !equalResourceLocation(resources, rs)) {
+ if (rs != null && !isDeletedFile(rs) && !equalResourceLocation(resources, rs)) {
sources.add(rs);
}
});
@@ -389,6 +391,18 @@ public class RouteWatcherReloadStrategy extends FileWatcherResourceReloadStrateg
}
}
+ /**
+ * Whether the resource is a file that no longer exists. Only the location is looked at: a source restored from its
+ * last loaded content is kept in memory and always exists, but its file may have been removed since (CAMEL-25427).
+ */
+ private static boolean isDeletedFile(Resource resource) {
+ String loc = resource.getLocation();
+ if (loc == null || !loc.startsWith("file:")) {
+ return false;
+ }
+ return !Files.exists(Paths.get(loc.substring(5)));
+ }
+
/**
* Whether the target is loading any of the given sources
*/