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

Claus Ibsen updated CAMEL-24404:
--------------------------------
    Fix Version/s: 4.23.0

> camel-base-engine: InternalRouteStartupManager re-throws consumer startup 
> exceptions raw instead of wrapping in FailedToStartRouteException
> -------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-24404
>                 URL: https://issues.apache.org/jira/browse/CAMEL-24404
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-base-engine
>            Reporter: mayur mohan
>            Priority: Minor
>             Fix For: 4.23.0
>
>
> h2. Problem
> In {code}InternalRouteStartupManager.doStartOrResumeRouteConsumers(){code}, 
> two catch blocks re-throw the consumer startup exception raw with a bare 
> {code}throw e{code}. When a consumer start() throws a message-less exception 
> such as a bare NullPointerException, the exception escapes directly to 
> callers instead of being wrapped in a proper FailedToStartRouteException.
> h2. Stack Trace
> {noformat}
> java.lang.NullPointerException
>     at 
> org.apache.camel.component.file.FileConsumer.doStart(FileConsumer.java:123)
>     at 
> org.apache.camel.support.service.BaseService.start(BaseService.java:119)
>     at 
> org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113)
>     at 
> org.apache.camel.impl.engine.InternalRouteStartupManager.doStartOrResumeRouteConsumers(InternalRouteStartupManager.java:429)
>     at 
> org.apache.camel.impl.engine.InternalRouteStartupManager.doStartRouteConsumers(InternalRouteStartupManager.java:378)
>     at 
> org.apache.camel.impl.engine.InternalRouteStartupManager.safelyStartRouteServices(InternalRouteStartupManager.java:214)
>     at 
> org.apache.camel.impl.engine.DefaultRouteController.doStartOrResumeRoutes(DefaultRouteController.java:272)
>     at 
> org.apache.camel.impl.engine.DefaultRouteController.startRoute(DefaultRouteController.java:147)
>     at 
> org.apache.camel.impl.engine.AbstractCamelContext.doStartCamel(AbstractCamelContext.java:3124)
>     at 
> org.apache.camel.impl.engine.AbstractCamelContext.doStart(AbstractCamelContext.java:2789)
>     at 
> org.apache.camel.support.service.BaseService.start(BaseService.java:119)
>     at 
> org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2460)
>     at 
> org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:198)
> {noformat}
> h2. Root Cause
> Both catch blocks in {code}doStartOrResumeRouteConsumers(){code} at lines 
> 427-432 and 465-470 use bare {code}throw e{code}. If the exception carries a 
> null message (e.g. {code}new NullPointerException(){code}), wrapping it in 
> {code}FailedToStartRouteException{code} would fail with a secondary NPE from 
> {code}Objects.requireNonNull{code} inside the constructor.
> Note: {code}RouteService.warmUp(){code} and {code}RouteService.setUp(){code} 
> have the same null-message problem and are fixed separately in PR 
> https://github.com/apache/camel/pull/25205.
> h2. Fix
> Replace both bare {code}throw e{code} sites with 
> {code}FailedToStartRouteException{code} wrapping using an 
> {code}extractUsefulMessage(){code} helper that walks the cause chain for a 
> non-null message.
> {code:java}
> } catch (Exception e) {
>     route.getProperties().put("route.start.exception", e);
>     throw new FailedToStartRouteException(
>             routeService.getId(), routeService.getLocation(),
>             extractUsefulMessage(e), e);
> }
> {code}
> h2. Files Changed
> * 
> {code}core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/InternalRouteStartupManager.java{code}
> ** Both throw e sites replaced with FailedToStartRouteException wrapping
> ** Added extractUsefulMessage() private static helper
> * 
> {code}core/camel-core/src/test/java/org/apache/camel/impl/engine/InternalRouteStartupManagerConsumerStartTest.java{code}
>  (new)
> ** testConsumerStartNullMessageProducesFailedToStartRouteException
> ** testConsumerStartWalksCauseChainForMessage
> h2. Pull Request
> https://github.com/apache/camel/pull/25554
> h2. Test Results
> {noformat}
> Tests run: 2, Failures: 0, Errors: 0, Skipped: 0  [JDK 21 / Maven 3.9]
> BUILD SUCCESS
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to