Skip to content

Fix #1296: ExceptionConverter.getStackTrace() no longer returns an empty array#1594

Open
andreasrosdalw wants to merge 1 commit into
LibrePDF:masterfrom
andreasrosdalw:fix-1296-exceptionconverter-stacktrace
Open

Fix #1296: ExceptionConverter.getStackTrace() no longer returns an empty array#1594
andreasrosdalw wants to merge 1 commit into
LibrePDF:masterfrom
andreasrosdalw:fix-1296-exceptionconverter-stacktrace

Conversation

@andreasrosdalw

@andreasrosdalw andreasrosdalw commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1296.

new ExceptionConverter(new IOException("test")).getStackTrace() returned an empty array, and getCause() returned null. Any logging framework or error reporter that relies on getStackTrace()/getCause() (i.e. essentially all of them) printed no stack trace at all when an ExceptionConverter propagated to user code. The information was only reachable through the class's custom printStackTrace() overrides.

Root cause

The class suppressed stack-trace collection (fillInStackTrace() returned this without 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:

  • The original exception is passed to super(ex) and becomes the causegetCause(), getStackTrace() and standard printStackTrace() now show the full picture: the conversion point plus Caused by: with the original exception. No information is lost.
  • The fillInStackTrace() and custom printStackTrace(...) overrides are removed; standard Throwable behavior takes over.
  • Backwards-compatible surface kept: getException() (now returns the cause), getMessage()/getLocalizedMessage() (still delegate to the wrapped exception), toString() (still prefixed with ExceptionConverter: for checked exceptions, unprefixed for runtime exceptions), and convertException(...).

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 ExceptionConverterTest covers: non-empty getStackTrace(), cause wiring, getException(), message/localized-message delegation, toString() prefix behavior for checked vs unchecked, printStackTrace containing both the original exception and the conversion frame, and convertException pass-through for runtime exceptions. The stack-trace and cause assertions fail on master. Full openpdf-core suite passes.

…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>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 1 complexity · 0 duplication

Metric Results
Complexity 1
Duplication 0

View in Codacy

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.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ExceptionConverter.getStackTrace() is empty

1 participant