Skip to content

fix: route sneaky-thrown checked exceptions from element effects to the error handler (#25508) (CP: 25.2) - #25515

Merged
vaadin-bot merged 1 commit into
25.2from
cherry-pick-25508-to-25.2-1788778118786
Sep 7, 2026
Merged

vaadin-bot merged 1 commit into
25.2from
cherry-pick-25508-to-25.2-1788778118786

Conversation

@vaadin-bot

Copy link
Copy Markdown
Collaborator

This PR cherry-picks changes from the original PR #25508 to branch 25.2.

Original PR description

ElementEffect only caught RuntimeException from the effect action, so a checked exception thrown without being declared ("sneaky throws", as produced by Kotlin or Lombok's @SneakyThrows) escaped past the effect machinery and ended up in the current thread's uncaught exception handler instead of the error handler of the component's Vaadin session.

Fixes #25506

What changed

  • ElementEffect.executeAction now catches Exception rather than RuntimeException, so a sneaky-thrown checked exception is handed to the session error handler unwrapped, exactly like a RuntimeException already was.
  • DeniedSignalUsageException keeps its dedicated catch ahead of the generic one, so it still propagates immediately to the caller (e.g. inside a bindChildren factory) instead of being swallowed by the error handler.
  • The probe/unattached path is restructured: when there is no error handler yet, the effect function now runs outside any try/catch and returns early, instead of being caught and re-thrown. This avoids needing a helper that re-throws checked exceptions undeclared, and removes a re-throw line that coverage analysis could never mark as executed (a line that only ever completes by throwing is not counted as covered).
  • Javadoc/comments updated to say exceptions are "not caught" in probe mode rather than "re-thrown", and to explain why the catch is on Exception.

No public or protected API changed — the behaviour change is entirely inside the private executeAction method.

Test summary

# Status What the test verifies Why it matters
1 ✅ A checked exception sneaky-thrown from an effect on an attached component is passed to the session error handler, and the ErrorEvent carries the same exception instance (not a wrapper) This is the bug being fixed; without it such exceptions bypass the application's error handling entirely
2 ✅ During the detached probe run (no error handler available yet) the checked exception propagates as-is out of Signal.effect, reaching the thread's uncaught exception handler unwrapped Widening the catch must not start swallowing or wrapping exceptions in probe mode, where the caller is expected to see them
3 ✅ A plain RuntimeException from an effect still reaches the error handler, both on a direct run and on an asynchronous re-run Guards against a regression in the pre-existing, far more common path (covered by tests already on main)
4 ✅ DeniedSignalUsageException is still thrown to the caller rather than routed to the error handler The new broad catch (Exception) sits right after this one; if ordering broke, illegal signal usage would silently become an error event

Tests added on this branch:

  • ElementEffectTest.effect_sneakyThrowCheckedException_delegatedToErrorHandler → row 1
  • ElementEffectTest.effect_notAttached_sneakyThrowCheckedException_rethrownUnwrapped → row 2
  • Private helper ElementEffectTest.sneakyThrow (throws an undeclared checked exception, mimicking Kotlin / @SneakyThrows) supports rows 1 and 2 and asserts nothing itself.

Rows 3 and 4 are pinned by tests that already existed on main (effect_throwExceptionWhenRunningDirectly_delegatedToErrorHandler, effect_throwExceptionWhenRunningAsynchronously_delegatedToErrorHandler, and the DeniedSignalUsageException assertion in the bindChildren factory test); they were left unchanged and serve as the regression net for this fix.

Deliberately untested: the asynchronous re-run path for checked exceptions specifically. It goes through the same executeAction code as row 1 and is already covered for RuntimeException by row 3, so a dedicated variant would only duplicate existing coverage. Javadoc/comment wording changes carry no behaviour and are not tested.

…he error handler (#25508)

`ElementEffect` only caught `RuntimeException` from the effect action,
so a checked exception thrown without being declared ("sneaky throws",
as produced by Kotlin or Lombok's `@SneakyThrows`) escaped past the
effect machinery and ended up in the current thread's uncaught exception
handler instead of the error handler of the component's Vaadin session.

Fixes #25506

## What changed

- `ElementEffect.executeAction` now catches `Exception` rather than
`RuntimeException`, so a sneaky-thrown checked exception is handed to
the session error handler unwrapped, exactly like a `RuntimeException`
already was.
- `DeniedSignalUsageException` keeps its dedicated `catch` ahead of the
generic one, so it still propagates immediately to the caller (e.g.
inside a `bindChildren` factory) instead of being swallowed by the error
handler.
- The probe/unattached path is restructured: when there is no error
handler yet, the effect function now runs *outside* any `try`/`catch`
and returns early, instead of being caught and re-thrown. This avoids
needing a helper that re-throws checked exceptions undeclared, and
removes a re-throw line that coverage analysis could never mark as
executed (a line that only ever completes by throwing is not counted as
covered).
- Javadoc/comments updated to say exceptions are "not caught" in probe
mode rather than "re-thrown", and to explain why the catch is on
`Exception`.

No public or protected API changed — the behaviour change is entirely
inside the private `executeAction` method.

## Test summary

| # | Status | What the test verifies | Why it matters |
|---|--------|------------------------|----------------|
| 1 | ✅ | A checked exception sneaky-thrown from an effect on an
attached component is passed to the session error handler, and the
`ErrorEvent` carries the *same* exception instance (not a wrapper) |
This is the bug being fixed; without it such exceptions bypass the
application's error handling entirely |
| 2 | ✅ | During the detached probe run (no error handler available yet)
the checked exception propagates as-is out of `Signal.effect`, reaching
the thread's uncaught exception handler unwrapped | Widening the catch
must not start swallowing or wrapping exceptions in probe mode, where
the caller is expected to see them |
| 3 | ✅ | A plain `RuntimeException` from an effect still reaches the
error handler, both on a direct run and on an asynchronous re-run |
Guards against a regression in the pre-existing, far more common path
(covered by tests already on `main`) |
| 4 | ✅ | `DeniedSignalUsageException` is still thrown to the caller
rather than routed to the error handler | The new broad `catch
(Exception)` sits right after this one; if ordering broke, illegal
signal usage would silently become an error event |

Tests added on this branch:

-
`ElementEffectTest.effect_sneakyThrowCheckedException_delegatedToErrorHandler`
→ row 1
-
`ElementEffectTest.effect_notAttached_sneakyThrowCheckedException_rethrownUnwrapped`
→ row 2
- Private helper `ElementEffectTest.sneakyThrow` (throws an undeclared
checked exception, mimicking Kotlin / `@SneakyThrows`) supports rows 1
and 2 and asserts nothing itself.

Rows 3 and 4 are pinned by tests that already existed on `main`
(`effect_throwExceptionWhenRunningDirectly_delegatedToErrorHandler`,
`effect_throwExceptionWhenRunningAsynchronously_delegatedToErrorHandler`,
and the `DeniedSignalUsageException` assertion in the `bindChildren`
factory test); they were left unchanged and serve as the regression net
for this fix.

Deliberately untested: the asynchronous re-run path for *checked*
exceptions specifically. It goes through the same `executeAction` code
as row 1 and is already covered for `RuntimeException` by row 3, so a
dedicated variant would only duplicate existing coverage.
Javadoc/comment wording changes carry no behaviour and are not tested.

---------

Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com>
@github-actions github-actions Bot added the +0.0.1 label Sep 7, 2026
@vaadin-bot

Copy link
Copy Markdown
Collaborator Author

This PR is eligible for auto-merging policy, so it has been approved automatically. If there are pending conditions, auto merge (with 'squash' method) has been enabled for this PR [Message is sent from bot]

@vaadin-bot
vaadin-bot enabled auto-merge (squash) September 7, 2026 10:57
@sonarqubecloud

sonarqubecloud Bot commented Sep 7, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Test Results

 1 383 files  ±0   1 383 suites  ±0   1h 30m 23s ⏱️ -1s
10 358 tests +2  10 290 ✅ +2  68 💤 ±0  0 ❌ ±0 
10 713 runs  +2  10 644 ✅ +2  69 💤 ±0  0 ❌ ±0 

Results for commit f50c4ad. ± Comparison against base commit 5695068.

@vaadin-bot
vaadin-bot merged commit c3ba733 into 25.2 Sep 7, 2026
35 checks passed
@vaadin-bot
vaadin-bot deleted the cherry-pick-25508-to-25.2-1788778118786 branch September 7, 2026 11:07
@vaadin-bot

Copy link
Copy Markdown
Collaborator Author

This ticket/PR has been released with Vaadin 25.2.8.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants