mayur mohan created CAMEL-24515:
-----------------------------------

             Summary: AbstractExchange.getIn(Class) and getOut(Class) throw NPE 
when CamelContext.getTypeConverter() is null during shutdown
                 Key: CAMEL-24515
                 URL: https://issues.apache.org/jira/browse/CAMEL-24515
             Project: Camel
          Issue Type: Bug
            Reporter: mayur mohan


h2. Problem

{{AbstractExchange.getIn(Class<T>)}} and {{AbstractExchange.getOut(Class<T>)}} 
call {{context.getTypeConverter().convertTo(...)}} directly without a null 
guard. When {{CamelContext}} is shutting down, 
{{DefaultCamelContextExtension.resetTypeConverter()}} sets the type converter 
to {{null}} during {{forceStopLazyInitialization()}}. Any thread that calls 
these methods during that window gets a bare {{NullPointerException}} with no 
actionable message.

This is the same race condition as CAMEL-24510 (fixed in 
{{ExchangeHelper.convertToType}}), but affecting two additional call sites that 
bypass {{ExchangeHelper}} entirely.

h2. Root Cause

File: 
{{core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java}}

Line ~499 (getIn):
{code:java}
return context.getTypeConverter().convertTo(type, this, in);
{code}

Line ~553 (getOut):
{code:java}
return context.getTypeConverter().convertTo(type, this, out);
{code}

h2. Stack Trace

{noformat}
java.lang.NullPointerException: Cannot invoke "TypeConverter.convertTo(...)"
    because "getTypeConverter()" is null
    at 
org.apache.camel.support.AbstractExchange.getIn(AbstractExchange.java:499)
{noformat}

h2. Fix

Add null guard on the {{TypeConverter}} in both methods, throwing 
{{IllegalStateException}} with a descriptive message instead of bare NPE.

h2. Related

CAMEL-24510 — same fix for {{ExchangeHelper.convertToType()}} and 
{{convertToMandatoryType()}}



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

Reply via email to