This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 6ddb848a250 CAMEL-20906: camel-core - Route reload NPE. Add WARN and 
avoid NPE.
6ddb848a250 is described below

commit 6ddb848a25013ce99f9c9796f94c17aee0f37f47
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Jun 24 11:39:19 2024 +0200

    CAMEL-20906: camel-core - Route reload NPE. Add WARN and avoid NPE.
---
 .../org/apache/camel/support/RouteWatcherReloadStrategy.java  | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 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 4cfede4ca83..0c79ca76529 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
@@ -301,6 +301,11 @@ public class RouteWatcherReloadStrategy extends 
FileWatcherResourceReloadStrateg
                     Route route = getCamelContext().getRoute(id);
                     if (route != null) {
                         ServiceStatus status = 
getCamelContext().getRouteController().getRouteStatus(id);
+                        if (status == null) {
+                            // undefined status of route (should not really 
happen)
+                            LOG.warn("Cannot get route status for route: {}. 
This route is skipped.", id);
+                            continue;
+                        }
                         if (ServiceStatus.Started.equals(status)) {
                             started++;
                         }
@@ -329,7 +334,9 @@ public class RouteWatcherReloadStrategy extends 
FileWatcherResourceReloadStrateg
             int total = ids.size();
             for (String id : ids) {
                 Route route = getCamelContext().getRoute(id);
-                EventHelper.notifyRouteReloaded(getCamelContext(), route, 
index++, total);
+                if (route != null) {
+                    EventHelper.notifyRouteReloaded(getCamelContext(), route, 
index++, total);
+                }
             }
 
             if (!removeAllRoutes) {
@@ -338,7 +345,7 @@ public class RouteWatcherReloadStrategy extends 
FileWatcherResourceReloadStrateg
                 StringJoiner sj = new StringJoiner("\n    ");
                 for (String id : ids) {
                     Route route = getCamelContext().getRoute(id);
-                    if (!route.isCustomId()) {
+                    if (route != null && !route.isCustomId()) {
                         sj.add(route.getEndpoint().getEndpointUri());
                     }
                 }

Reply via email to