You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support backtrace_locations with Java exceptions #9458
JRuby had supported duck-typing of java.lang.Throwable hierarchy, to act like Ruby's Exception, for a long time.
There's java.lang.Throwable#backtrace which maps the Java stack-trace into an Array.
The backtrace_locations method are a later Ruby language feature and so wasn't considered for addiiton.
It would be desired to support backtrace_location with JRuby's Java integration as well, esp. since frameworks such as Rails might do rescue Exception (which catched Java throwables) and assume backtrace_locations exists.
I tried to get Claude to dig across other major libraries/frameworks but it seemed to only find Rails as a core user of backtrace_locations, aside from some MRI-only libraries, and things like sorbet. And for Rails only introduced in Rails 7.1 (Oct 2023) so it's not exactly old. Other libraries all seem to mainly still do string-parsing.
JRuby is missing .exception(message = nil) → self or new_exception on these as well, but perhaps that is not important
pbly worthy of a separate ticket, personally never used it, instantiating another Java exception (just to change the message) might be tricky. would personally avoid that and not implement feature parity with Ruby Exception. 🤷
Technically I guess backtrace_locations is missing on JRuby 9.4 as well since it's been in Ruby since 2.1, but I didn't specifically test it there (with Rails). That's what the user in the linked issue reported against though.
I have had weird occasional problems with missing exceptions in a real world Rails 7.2 on JRuby 9.4 app though, just never dug into them sufficiently to know the cause. Might be this, might not be. Took me quite a while to get to Rails 7.1 due to jruby-rack session issues though, so I can perhaps see why id not have noticed it as production apps generally won't go through this Rails code.
Not quite sure why it went unreported so long though since Rails 7.1 is 2.5 years old now, and maybe 15 months old before that linked issue. I'd have thought there's lots of ways one can end up with a Java Throwable coming out of Rails that ends.up handled here during development? Unless there is some other middleware that is usually handling them earlier before this, even in dev.
JRuby is missing .exception(message = nil) → self or new_exception on these as well, but perhaps that is not important
pbly worthy of a separate ticket, personally never used it, instantiating another Java exception (just to change the message) might be tricky. would personally avoid that and not implement feature parity with Ruby Exception. 🤷
Yeah that one seems weird - maybe not worth worrying about.
I have had weird occasional problems with missing exceptions in a real world Rails 7.2 on JRuby 9.4 app though, just never dug into them sufficiently to know the cause
Not sure how serious this would be, given the ~ EOL status on 9.4. I can leave this issue open for consideration but technically it's a "breaking" change e.g. user-code doing exception.respond_to?(:backtrace_location)...
You're likely quite deep in the tranches (very much appreciated) with the investigations around jruby-rack etc. 😄
I am using Rails daily (although embedded only these days) and usually smt like a java.lang.Error not being handled seems rare (acceptable). It's going to depend on specifics of where/when such unexpected Java throwables surface.
I believe we should just include this in 10.0+ and not 9.4. If a commercial user depends on 9.4 and requires this to be backported, they will need to work through appropriate channels.
If the cherry pick is/was easy, I was hoping I might do the work to cherry pick it into 9.4.15.0, if that “last patch” is still planned. If it’s not an easy backport, then can leave it.
For selfish reasons, if nothing else, given I lost quite a number of hours the other day debugging warbler because of problems like this, and also to a lesser extent because GoCD still uses 9.4 (as Ive mentioned before, because Java 21+Ruby 3.4 is/was too aggressive as a minimum and thus was a big jump).
If you can do the work to cherrypick it and verify it can get into the 9.4.15 release coming up in the next week or two. We should stop merging forward from 9.4 branch at this point since it is EOL and will only get targeted fixes and subsidized releases after 9.4.15.
No merging forward means this PR should target 10.0, since we are still merging that forward to 10.1.
Activity
chadlwilson commentedon May 23, 2026
For reference, collecting together some of my notes.
Related issues
backtrace_locations.NoSuchMethodErrordue to a removal on JRuby 10.1, which leads to Rails losing the error message for the JavaNoSuchMethodErrorentirely, not just the backtraceI tried to get Claude to dig across other major libraries/frameworks but it seemed to only find Rails as a core user of
backtrace_locations, aside from some MRI-only libraries, and things likesorbet. And for Rails only introduced in Rails 7.1 (Oct 2023) so it's not exactly old. Other libraries all seem to mainly still do string-parsing.Some CRuby additional context
set_backtracecan take an array ofThread::Backtrace::Locationfrom3.4+- https://ruby-doc.org/3.4.1/Exception.html#method-i-set_backtrace may need to add support?: https://bugs.ruby-lang.org/issues/13557.exception(message = nil) → self or new_exceptionon these as well, but perhaps that is not importantSome uses in the ecosystem:
Existing JRuby Code
Existing
backtraceimpl/placebacktrace_locationswould need to be implementation:jruby/core/src/main/java/org/jruby/javasupport/ext/JavaLang.java
Lines 220 to 236 in db591d8
Existing Cruby spec, which could have an equivalent for Java throwables:
jruby/spec/ruby/core/exception/backtrace_locations_spec.rb
Lines 4 to 39 in 849ef4a
Existing
Backtrace.backtrace_locationsjava impl:jruby/core/src/main/java/org/jruby/RubyException.java
Lines 78 to 113 in b814bff
Existing
Thread.backtrace_locationsjava impl:jruby/core/src/main/java/org/jruby/RubyThread.java
Lines 2150 to 2173 in f2ff425
kares commentedon May 26, 2026
so, based on #8665 (comment) (due Rails) it would make sense to have this in 10.0+ rather than just 10.1
kares commentedon May 26, 2026
pbly worthy of a separate ticket, personally never used it, instantiating another Java exception (just to change the
message) might be tricky. would personally avoid that and not implement feature parity with RubyException. 🤷chadlwilson commentedon May 26, 2026
Technically I guess
backtrace_locationsis missing on JRuby 9.4 as well since it's been in Ruby since 2.1, but I didn't specifically test it there (with Rails). That's what the user in the linked issue reported against though.I have had weird occasional problems with missing exceptions in a real world Rails 7.2 on JRuby 9.4 app though, just never dug into them sufficiently to know the cause. Might be this, might not be. Took me quite a while to get to Rails 7.1 due to jruby-rack session issues though, so I can perhaps see why id not have noticed it as production apps generally won't go through this Rails code.
Not quite sure why it went unreported so long though since Rails 7.1 is 2.5 years old now, and maybe 15 months old before that linked issue. I'd have thought there's lots of ways one can end up with a Java Throwable coming out of Rails that ends.up handled here during development? Unless there is some other middleware that is usually handling them earlier before this, even in dev.
chadlwilson commentedon May 26, 2026
Yeah that one seems weird - maybe not worth worrying about.
kares commentedon May 27, 2026
Not sure how serious this would be, given the ~ EOL status on 9.4. I can leave this issue open for consideration but technically it's a "breaking" change e.g. user-code doing
exception.respond_to?(:backtrace_location)...You're likely quite deep in the tranches (very much appreciated) with the investigations around jruby-rack etc. 😄
I am using Rails daily (although embedded only these days) and usually smt like a
java.lang.Errornot being handled seems rare (acceptable). It's going to depend on specifics of where/when such unexpected Java throwables surface.headius commentedon May 27, 2026
I believe we should just include this in 10.0+ and not 9.4. If a commercial user depends on 9.4 and requires this to be backported, they will need to work through appropriate channels.
chadlwilson commentedon May 27, 2026
If the cherry pick is/was easy, I was hoping I might do the work to cherry pick it into 9.4.15.0, if that “last patch” is still planned. If it’s not an easy backport, then can leave it.
For selfish reasons, if nothing else, given I lost quite a number of hours the other day debugging warbler because of problems like this, and also to a lesser extent because GoCD still uses 9.4 (as Ive mentioned before, because Java 21+Ruby 3.4 is/was too aggressive as a minimum and thus was a big jump).
Would that be considered?
headius commentedon May 27, 2026
If you can do the work to cherrypick it and verify it can get into the 9.4.15 release coming up in the next week or two. We should stop merging forward from 9.4 branch at this point since it is EOL and will only get targeted fixes and subsidized releases after 9.4.15.
No merging forward means this PR should target 10.0, since we are still merging that forward to 10.1.
chadlwilson commentedon May 27, 2026
Yup, that makes sense to me - I wasn't suggesting targeting 9.4 and merging forward, if that’s how it read. 👍
headius commentedon Jun 11, 2026
Fixed by #9461.