Skip to content

Rethrow JVM errors unchanged in MethodHandleFactory.invokeExact - #70

Merged
garydgregory merged 1 commit into
apache:mainfrom
ppkarwasz:fix/invoke-exact-error-passthrough
Sep 1, 2026
Merged

Rethrow JVM errors unchanged in MethodHandleFactory.invokeExact#70
garydgregory merged 1 commit into
apache:mainfrom
ppkarwasz:fix/invoke-exact-error-passthrough

Conversation

@ppkarwasz

Copy link
Copy Markdown
Member

MethodHandleFactory.invokeExact wrapped every throwable that was not of the declared rethrow type in IllegalStateException — including undeclared JVM Errors. An OutOfMemoryError raised mid-lookup was thereby demoted from Error to RuntimeException, hiding it from supervisors that handle Error separately and conflating it with securing failures (SecureException also extends IllegalStateException).

The fix rethrows an undeclared Error unchanged before the wrap, leaving IllegalStateException to cover runtime exceptions only (the looked-up newDefault* factory methods declare no other checked exceptions). Tests now assert instance identity, not just type, on both rethrow paths, and a new test drives an OutOfMemoryError through the helper.

This completes the remainder of a scan finding whose headline defect — the inverted e.getClass().isInstance(rethrow) check that made the declared-type rethrow dead code — was already fixed in cd2a7a4.

🤖 Generated with Claude Code

An undeclared Error raised through the MethodHandle lookup path (an
OutOfMemoryError, for example) was wrapped in IllegalStateException,
demoting it from Error to RuntimeException and hiding it from
supervisors that handle Error separately. Rethrow it unchanged; the
IllegalStateException wrap now covers runtime exceptions only, since
the looked-up factory methods declare no other checked exceptions.
Assert instance identity, not just type, on both rethrow paths.

Assisted-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CLnTBsvmYtxzNTWVGNyz33
@garydgregory
garydgregory merged commit 54b8d4b into apache:main Sep 1, 2026
17 checks passed
@ppkarwasz
ppkarwasz deleted the fix/invoke-exact-error-passthrough branch September 1, 2026 13:17
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.

2 participants