Skip to content

✅ Fix JRuby local backtrace test assertions - #732

Open
nevans wants to merge 1 commit into
masterfrom
jruby/pend-assert_local_raise
Open

✅ Fix JRuby local backtrace test assertions#732
nevans wants to merge 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.
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