davsclaus commented on code in PR #25760:
URL: https://github.com/apache/camel/pull/25760#discussion_r3865784123


##########
core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java:
##########
@@ -261,7 +262,15 @@ public static <T> T getHeaderOrProperty(Exchange exchange, 
String name, Class<T>
      */
     public static <T> T convertToMandatoryType(Exchange exchange, Class<T> 
type, Object value)
             throws TypeConversionException, NoTypeConversionAvailableException 
{
-        return 
exchange.getContext().getTypeConverter().mandatoryConvertTo(type, exchange, 
value);
+        CamelContext ctx = exchange != null ? exchange.getContext() : null;
+        TypeConverter converter = ctx != null ? ctx.getTypeConverter() : null;
+        if (converter == null) {

Review Comment:
   Same whack-a-mole pattern flagged on the follow-up PR #25771 — see the 
top-level review comment for the full analysis. The type converter itself stays 
functional after `stop()` (its `doStop()` just logs stats); the NPE only exists 
because `resetTypeConverter()` nulls the field at the tail of `doStop()`. 
Deferring that null-out to the start of the next `doStart()` instead (rather 
than the tail of `doStop()`) removes the need for this guard — and every other 
unguarded `getTypeConverter()` call site — in one place.



##########
core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java:
##########
@@ -271,7 +280,16 @@ public static <T> T convertToMandatoryType(Exchange 
exchange, Class<T> type, Obj
      * @throws org.apache.camel.TypeConversionException is thrown if error 
during type conversion
      */
     public static <T> T convertToType(Exchange exchange, Class<T> type, Object 
value) throws TypeConversionException {
-        return exchange.getContext().getTypeConverter().convertTo(type, 
exchange, value);
+        CamelContext ctx = exchange != null ? exchange.getContext() : null;
+        TypeConverter converter = ctx != null ? ctx.getTypeConverter() : null;
+        if (converter == null) {

Review Comment:
   Same concern as `convertToMandatoryType` above.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to