[ 
https://issues.apache.org/jira/browse/CAMEL-15450?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

wupenghuai closed CAMEL-15450.
------------------------------
    Estimated Complexity: Novice  (was: Unknown)

> ClusteredRoutePolicyFactory throw NullPointerException when adding a route to 
> CamelContext that has been started
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-15450
>                 URL: https://issues.apache.org/jira/browse/CAMEL-15450
>             Project: Camel
>          Issue Type: Bug
>          Components: came-core
>    Affects Versions: 2.25.2
>            Reporter: wupenghuai
>            Assignee: Claus Ibsen
>            Priority: Major
>             Fix For: 3.5.0
>
>
> Hello,
> I recently found that when using ClusteredRoutePolicyFactory , adding a route 
> to a CamelContext that has been started gives an error.
>  
> follow is exceptionn stak
> {code:java}
> org.apache.camel.FailedToCreateRouteException: Failed to create route ns1/1: 
> Route(ns1/1)[[From[timer:pocTimer?period=10s]] -> [SetHeader... because of 
> java.lang.RuntimeException: 
> java.lang.NullPointerExceptionorg.apache.camel.FailedToCreateRouteException: 
> Failed to create route ns1/1: Route(ns1/1)[[From[timer:pocTimer?period=10s]] 
> -> [SetHeader... because of java.lang.RuntimeException: 
> java.lang.NullPointerException at 
> org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:217) at 
> org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1139)
>  at 
> org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3736)
>  at 
> org.apache.camel.impl.DefaultCamelContext.addRouteDefinitions(DefaultCamelContext.java:1071)
>  at com.netease.cloud.nsf.server.DefaultServer.onAdd(DefaultServer.java:65) 
> at 
> com.netease.cloud.nsf.resource.DefaultResourceManager.lambda$compareAndNotify$0(DefaultResourceManager.java:51)
>  at 
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
>  at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
>  at java.lang.Thread.run(Thread.java:748)Caused by: 
> org.apache.camel.RuntimeCamelException: java.lang.RuntimeException: 
> java.lang.NullPointerException at 
> org.apache.camel.impl.cluster.ClusteredRoutePolicyFactory.createRoutePolicy(ClusteredRoutePolicyFactory.java:65)
>  at 
> org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1304) 
> at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:212) 
> ... 8 moreCaused by: java.lang.RuntimeException: 
> java.lang.NullPointerException at 
> org.apache.camel.impl.cluster.ClusteredRoutePolicy.setCamelContext(ClusteredRoutePolicy.java:140)
>  at 
> org.apache.camel.impl.cluster.ClusteredRoutePolicy.forNamespace(ClusteredRoutePolicy.java:350)
>  at 
> org.apache.camel.impl.cluster.ClusteredRoutePolicyFactory.createRoutePolicy(ClusteredRoutePolicyFactory.java:63)
>  ... 10 moreCaused by: java.lang.NullPointerException at 
> org.apache.camel.impl.cluster.ClusteredRoutePolicy.onCamelContextStarted(ClusteredRoutePolicy.java:285)
>  at 
> org.apache.camel.impl.cluster.ClusteredRoutePolicy.access$800(ClusteredRoutePolicy.java:49)
>  at 
> org.apache.camel.impl.cluster.ClusteredRoutePolicy$CamelContextStartupListener.onCamelContextStarted(ClusteredRoutePolicy.java:338)
>  at 
> org.apache.camel.impl.cluster.ClusteredRoutePolicy$CamelContextStartupListener.onCamelContextStarted(ClusteredRoutePolicy.java:323)
>  at 
> org.apache.camel.impl.DefaultCamelContext.addStartupListener(DefaultCamelContext.java:1565)
>  at 
> org.apache.camel.impl.cluster.ClusteredRoutePolicy.setCamelContext(ClusteredRoutePolicy.java:136)
>  ... 12 more
> {code}
>  
>  
> then i locate the cause:
> ClusteredRoutePolicyFactory will call  ClusteredRoutePolicy.forNamespace
> ClusteredRoutePolicy.forNamespace rely on ClusteredRoutePolicy.setCamelContext
> SetCamelContext will determine if the CamelContext has been started, and if 
> so, the following logic will be executed
> {code:java}
> private void onCamelContextStarted() {
>     LOGGER.debug("Apply cluster policy (stopped-routes='{}', 
> started-routes='{}')",
>         
> stoppedRoutes.stream().map(Route::getId).collect(Collectors.joining(",")),
>         
> startedRoutes.stream().map(Route::getId).collect(Collectors.joining(","))
>     );
>     clusterView.addEventListener(leadershipEventListener);
> }
> {code}
> But at this point the clusterView is still not initialized.It will be 
> initialized when the ClusteredRoutePolicy.start() is called.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to