CAMEL-24651: Fix NPE in ExceptionHelper.stackTraceToString() when exception is null - #26221
Conversation
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
✅ Generated files are up to dateAn earlier CI run reported uncommitted generated changes; the latest run no longer does. |
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 564 tested, 27 compile-only — current: 564 all testedMaveniverse Scalpel detected 591 affected modules (current approach: 564).
|
| Module | Duration | Status |
|---|---|---|
| Camel :: Support | 17.0s | SUCCESS |
| Camel :: Core | n/a |
Top 20 slowest modules:
Camel :: Support(17.0s)
63c760d to
1cefa0b
Compare
apupier
left a comment
There was a problem hiding this comment.
there is a useless comment but not a blocker for the merge
…eption is null
When ${exception.stacktrace} is evaluated on an exchange that has no
exception, LanguageHelper.exceptionStacktrace() calls
ExceptionHelper.stackTraceToString(null), which then NPEs on
e.printStackTrace(printWriter).
Add a null guard in ExceptionHelper.stackTraceToString() so that it
returns null when the supplied Throwable is null, consistent with the
existing behaviour of LanguageHelper.exceptionMessage().
1cefa0b to
8da1a4e
Compare
🔄 Backport BotThis bugfix was merged into
Labels Port PRs will be created shortly. |
Fixes CAMEL-24651: regression introduced by commit f9048eb ("consolidate duplicated code for printing the stack traces").
Problem
When
${exception.stacktrace}is evaluated on an exchange that has no exception:LanguageHelper.exceptionStacktrace()callsexception(exchange)which returnsnullnullis passed toExceptionHelper.stackTraceToString(null)stackTraceToString()callse.printStackTrace(printWriter)→ NPEPrior to the refactoring, the call site had an explicit null check that was lost during consolidation.
LanguageHelper.exceptionMessage()still has its null guard and is unaffected.Fix
Add a null guard at the top of
ExceptionHelper.stackTraceToString()so it returnsnullwhen the suppliedThrowableisnull. This is the defensive approach: it protects all callers rather than just the one inLanguageHelper.Test
Added
SimpleTest#testExceptionStacktraceNoExceptionto cover the regression: evaluating${exception.stacktrace}on an exchange with no exception must returnnull(not throw NPE).