You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (Jira)" <ji...@apache.org> on 2026/09/09 19:12:00 UTC

[jira] [Updated] (CAMEL-24651) Regression on Camel 4.x NPE on evaluation of a Simple expression ${exception.stacktrace}

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

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

> Regression on Camel 4.x NPE on evaluation of a Simple expression ${exception.stacktrace}
> ----------------------------------------------------------------------------------------
>
>                 Key: CAMEL-24651
>                 URL: https://issues.apache.org/jira/browse/CAMEL-24651
>             Project: Camel
>          Issue Type: Bug
>    Affects Versions: 4.18.4, 4.22.0
>            Reporter: Xilai Dai
>            Assignee: Guillaume Nodet
>            Priority: Minor
>             Fix For: 4.23.0
>
>
> {code:java}
> from("timer:Timer_1?repeatCount=1&delay=1000")
> .process(new org.apache.camel.Processor() {				
>         public void process(org.apache.camel.Exchange exchange) throws Exception {
> 		        // throw new IllegalArgumentException("Simulated processing error");
> 	}
> })		
> .setBody().simple("${exception.stacktrace}"); {code}
> {code:java}
> java.lang.NullPointerException: Cannot invoke "java.lang.Throwable.printStackTrace(java.io.PrintWriter)" because "e" is null	
> at org.apache.camel.support.ExceptionHelper.stackTraceToString(ExceptionHelper.java:41)	
> at org.apache.camel.support.LanguageHelper.exceptionStacktrace(LanguageHelper.java:80)	
> at org.apache.camel.support.builder.ExpressionBuilder$16.evaluate(ExpressionBuilder.java:641)	
> at org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:45)	
> at org.apache.camel.processor.SetBodyProcessor.process(SetBodyProcessor.java:45)	
> at org.apache.camel.support.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:104) {code}
> The issue is not present on Camel 3.x and the null value of exception.stacktrace is properly handled.
> Proposed fixes:
> {code:java}
> // org.apache.camel.support.LanguageHelper
> public static String exceptionStacktrace(Exchange exchange) {
>     Exception exception = exception(exchange);
>     if (exception == null) {
>         return null;
>     }
>     return ExceptionHelper.stackTraceToString(exception);
> } {code}
> {code:java}
> // org.apache.camel.support.ExceptionHelper
> public static String stackTraceToString(Throwable e) {
>     if (e == null) {
>         return null;
>     }
>     final StringWriter writer = new StringWriter();
>     final PrintWriter printWriter = new PrintWriter(writer, true);
>     e.printStackTrace(printWriter);
>     return writer.toString();
> } {code}



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