gnodet-bot commented on code in PR #31297:
URL: https://github.com/apache/camel/pull/31297#discussion_r4776200430


##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/SendProcessor.java:
##########
@@ -200,18 +200,26 @@ private boolean sendUsingPattern(
                 (producer, ex, cb) -> producer.process(ex, doneSync -> {
                     // restore previous MEP
                     exchange.setPattern(existingPattern);
-                    // result should be stored in variable instead of message 
body/headers
-                    if (ExchangeHelper.shouldSetVariableResult(exchange, 
variableReceive)) {
-                        
ExchangeHelper.setVariableFromMessageBodyAndHeaders(exchange, variableReceive,
-                                exchange.getMessage());
-                        exchange.getMessage().setBody(originalBody);
-                        exchange.getMessage().setHeaders(originalHeaders);
-                    }
+                    storeVariableResult(exchange, variableReceive, 
originalBody, originalHeaders);
                     // signal we are done
                     cb.done(doneSync);
                 }));
     }
 
+    static void storeVariableResult(
+            Exchange exchange, String variableReceive, Object originalBody, 
Map<String, Object> originalHeaders) {
+        if (ExchangeHelper.shouldSetVariableResult(exchange, variableReceive)) 
{
+            try {
+                ExchangeHelper.setVariableFromMessageBodyAndHeaders(exchange, 
variableReceive, exchange.getMessage());
+            } catch (Exception e) {
+                exchange.setException(e);
+            } finally {
+                exchange.getMessage().setBody(originalBody);
+                exchange.getMessage().setHeaders(originalHeaders);
+            }
+        }
+    }

Review Comment:
   ℹ️ `Enricher` and `PollEnricher` have the same inline variable-store pattern 
and are not updated to use this method. In `Enricher`, if 
`setVariableFromMessageBodyAndHeaders` throws, the outer `catch (Throwable)` 
block catches the exception but the body/header restore lines are skipped — 
`originalBody`/`originalHeaders` are lost. Consider updating those two callers 
to use `storeVariableResult` for the same resilience guarantee.



##########
core/camel-support/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java:
##########
@@ -48,6 +48,10 @@ public static StreamCache 
convertToStreamCache(ByteArrayInputStream stream, Exch
 
     @Converter(order = 2)
     public static StreamCache convertToStreamCache(InputStream stream, 
Exchange exchange) throws IOException {
+        // A variable repository can request a cache without an exchange to 
own its resources.
+        if (exchange == null) {
+            return null;
+        }

Review Comment:
   ⚠️ The same null-exchange gap exists in the `Reader` converter (order=4, 
below). `exchange.getContext().getTypeConverter()` will NPE when called without 
an exchange. Add the same guard at the top of that method:
   
   ```java
   if (exchange == null) {
       return null;
   }
   ```



-- 
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