Fix #1296: ExceptionConverter.getStackTrace() no longer returns an empty array#1594
Open
andreasrosdalw wants to merge 1 commit into
Open
Conversation
…ns an empty array ExceptionConverter suppressed fillInStackTrace() and kept the wrapped exception in a private field instead of setting it as the cause. As a result getStackTrace() returned an empty array and getCause() returned null, so logging frameworks printed no stack trace at all when an ExceptionConverter propagated to user code. Information was only visible through the custom printStackTrace() overrides. Make it a regular wrapper: pass the original exception to super() as the cause and drop the fillInStackTrace()/printStackTrace() overrides. getStackTrace(), getCause() and standard printStackTrace() now show the full picture (conversion point plus 'Caused by:' with the original exception). getException(), getMessage(), getLocalizedMessage() and the 'ExceptionConverter: ' toString() prefix keep their behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 1 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Fixes #1296.
new ExceptionConverter(new IOException("test")).getStackTrace()returned an empty array, andgetCause()returned null. Any logging framework or error reporter that relies ongetStackTrace()/getCause()(i.e. essentially all of them) printed no stack trace at all when anExceptionConverterpropagated to user code. The information was only reachable through the class's customprintStackTrace()overrides.Root cause
The class suppressed stack-trace collection (
fillInStackTrace()returnedthiswithout filling) and kept the wrapped exception in a private field instead of setting it as the exception cause.Fix
As suggested in the issue, make it a regular wrapper:
super(ex)and becomes the cause —getCause(),getStackTrace()and standardprintStackTrace()now show the full picture: the conversion point plusCaused by:with the original exception. No information is lost.fillInStackTrace()and customprintStackTrace(...)overrides are removed; standardThrowablebehavior takes over.getException()(now returns the cause),getMessage()/getLocalizedMessage()(still delegate to the wrapped exception),toString()(still prefixed withExceptionConverter:for checked exceptions, unprefixed for runtime exceptions), andconvertException(...).Behavior note:
printStackTrace()output now follows the standard JDK format (wrapper frames +Caused by:section) instead of printing only the wrapped exception's trace with a prefix — strictly more information, in the format every Java developer and tool expects.Tests
New
ExceptionConverterTestcovers: non-emptygetStackTrace(), cause wiring,getException(), message/localized-message delegation,toString()prefix behavior for checked vs unchecked,printStackTracecontaining both the original exception and the conversion frame, andconvertExceptionpass-through for runtime exceptions. The stack-trace and cause assertions fail on master. Fullopenpdf-coresuite passes.