Skip to content

[ji] support java.lang.Throwable#backtrace_locations#9461

Merged
kares merged 1 commit into
jruby:jruby-10.0from
kares:ji-backtrace_locations
May 27, 2026
Merged

[ji] support java.lang.Throwable#backtrace_locations#9461
kares merged 1 commit into
jruby:jruby-10.0from
kares:ji-backtrace_locations

Conversation

@kares
Copy link
Copy Markdown
Member

@kares kares commented May 25, 2026

the one thing left, in terms of Ruby exception compatibility, would be Exception#exception(str) which might be a bit tricky to fully support.

@kares kares changed the title [feat] support java.lang.Throwable#backtrace_locations [ji] support java.lang.Throwable#backtrace_locations May 25, 2026
@kares kares linked an issue May 25, 2026 that may be closed by this pull request
@kares kares force-pushed the ji-backtrace_locations branch from 9e515d7 to 129df00 Compare May 25, 2026 05:56
@kares kares force-pushed the ji-backtrace_locations branch from 129df00 to de37a96 Compare May 25, 2026 10:16
@kares
Copy link
Copy Markdown
Member Author

kares commented May 26, 2026

Based on Rails usage, as mentioned in #9458 would likely make sense to re-target this to 10.0.x

Copy link
Copy Markdown
Member

@headius headius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestions to clean it up a bit but generally looks fine. In the future we might want to also use our JRuby-aware stack trace processing to rewrite JIT and interpreter frames but that's out of scope here.

}

@JRubyMethod
public static IRubyObject backtrace_locations(final ThreadContext context, final IRubyObject self) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and backtrace are very similar. Maybe share the common parts and just construct the elements differently.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah the preamble, but even if we dry out the loop mapping with a function you still need to return a different array.

IRubyObject[] ary = new IRubyObject[length];
for ( int i = 0; i < length; i++ ) {
ary[i] = newLocation(runtime, elements[i + offset]);
ary[i] = new Location(runtime, locationClass, elements[i + offset]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a new overload of newLocation make sense here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, literally would be the same as doing new Location() directly.

@kares kares force-pushed the ji-backtrace_locations branch from de37a96 to e64e131 Compare May 27, 2026 07:40
@kares kares changed the base branch from master to jruby-10.0 May 27, 2026 07:40
@kares kares added this to the JRuby 10.0.6.0 milestone May 27, 2026
@kares kares merged commit 6d7819e into jruby:jruby-10.0 May 27, 2026
217 of 220 checks passed
@kares kares deleted the ji-backtrace_locations branch May 27, 2026 09:34
chadlwilson pushed a commit to chadlwilson/jruby that referenced this pull request May 28, 2026
(cherry-picked from commit 6d7819e)

Signed-off-by: Chad Wilson <29788154+chadlwilson@users.noreply.github.com>
chadlwilson pushed a commit to chadlwilson/jruby that referenced this pull request May 28, 2026
(cherry-picked from commit 6d7819e)

Signed-off-by: Chad Wilson <29788154+chadlwilson@users.noreply.github.com>
chadlwilson pushed a commit to chadlwilson/jruby that referenced this pull request May 28, 2026
(cherry-picked from commit 6d7819e)

Signed-off-by: Chad Wilson <29788154+chadlwilson@users.noreply.github.com>
headius added a commit that referenced this pull request May 28, 2026
…e-locations

[9.4] backport [ji] support java.lang.Throwable#backtrace_locations (#9461)
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.

Support backtrace_locations with Java exceptions

2 participants