Skip to content

✅ Fix JRuby local backtrace test assertions - #732

Merged
nevans merged 1 commit into
masterfrom
jruby/pend-assert_local_raise
Aug 26, 2026
Merged

✅ Fix JRuby local backtrace test assertions#732
nevans merged 1 commit into
masterfrom
jruby/pend-assert_local_raise

Conversation

@nevans

@nevans nevans commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

A bug was fixed in jruby-head, but that may not be in current releases:

With that issue fixed, these tests don't need to be marked pending! 😄

BUT, JRuby does still have some incongruity between caller(1) and raise rescue $!.backtrace[1..]. Some ruby block stack frames in caller are replaced by java stack frames in Exception#backtrace. For example:

--- Kernel#caller
+++ Exception#backtrace
  /home/nick/.local/share/rubies/jruby-dev/lib/ruby/gems/shared/gems/test-unit-3.7.8/lib/test/unit/testcase.rb:632:in 'block in run'
- /home/nick/.local/share/rubies/jruby-dev/lib/ruby/gems/shared/gems/test-unit-3.7.8/lib/test/unit/testcase.rb:631:in 'catch'
+ org/jruby/RubyKernel.java:1604:in 'catch'
+ org/jruby/RubyKernel.java:1599:in 'catch'
  /home/nick/.local/share/rubies/jruby-dev/lib/ruby/gems/shared/gems/test-unit-3.7.8/lib/test/unit/testcase.rb:631:in 'run'

The workaround is relatively simple: use a locally generated exception to generate the stack frames for comparison.

A bug was fixed in jruby-head, but that may not be in current releases:
* JRuby Issue: jruby/jruby#9528
* Fixed by: jruby/jruby#9528

With that issue fixed, these tests don't need to be marked pending! 😄

BUT, JRuby _does_ still have some incongruity between `caller(1)` and
`raise rescue $!.backtrace[1..]`.  Some ruby block stack frames in
`caller` are replaced by java stack frames in `Exception#backtrace`.
For example:

```diff
--- Kernel#caller
+++ Exception#backtrace
  /home/nick/.local/share/rubies/jruby-dev/lib/ruby/gems/shared/gems/test-unit-3.7.8/lib/test/unit/testcase.rb:632:in 'block in run'
- /home/nick/.local/share/rubies/jruby-dev/lib/ruby/gems/shared/gems/test-unit-3.7.8/lib/test/unit/testcase.rb:631:in 'catch'
+ org/jruby/RubyKernel.java:1604:in 'catch'
+ org/jruby/RubyKernel.java:1599:in 'catch'
  /home/nick/.local/share/rubies/jruby-dev/lib/ruby/gems/shared/gems/test-unit-3.7.8/lib/test/unit/testcase.rb:631:in 'run'
```

The workaround is relatively simple: use a locally generated exception
to generate the stack frames for comparison.
@nevans
nevans force-pushed the jruby/pend-assert_local_raise branch from 00db7dd to 9b9e6cb Compare August 26, 2026 22:14
@nevans

nevans commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator Author

@headius I found this curious incongruity last week: caller(1..) == (raise rescue $!.backtrace[1..]) isn't always true for JRuby. It's not a big deal, so I didn't make a JRuby issue for it.

But caller locations and exception backtrace locations seem to always agree under CRuby and TruffleRuby. Do you think it's worth making a ruby spec update?

@nevans
nevans merged commit 6d2ef7a into master Aug 26, 2026
34 checks passed
@nevans
nevans deleted the jruby/pend-assert_local_raise branch August 26, 2026 22:22
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.

1 participant