From e14e9982a56818f4ae919152de8acbef7ed8abba Mon Sep 17 00:00:00 2001 From: Chad Wilson <29788154+chadlwilson@users.noreply.github.com> Date: Sat, 23 May 2026 14:54:15 +0800 Subject: [PATCH] test: add temporary workaround to ensure we can see backtraces --- .../java_throwable_backtrace_locations.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 integration/rails7_test/src/main/ruby/config/initializers/java_throwable_backtrace_locations.rb diff --git a/integration/rails7_test/src/main/ruby/config/initializers/java_throwable_backtrace_locations.rb b/integration/rails7_test/src/main/ruby/config/initializers/java_throwable_backtrace_locations.rb new file mode 100644 index 00000000..0b7b3894 --- /dev/null +++ b/integration/rails7_test/src/main/ruby/config/initializers/java_throwable_backtrace_locations.rb @@ -0,0 +1,15 @@ +if defined?(Java) + Java::JavaLang::Throwable.class_eval do + # Ruby's #backtrace_locations isn't defined on Java Throwables. Rails 7.2's + # ActionDispatch::ExceptionWrapper#build_backtrace assumes it exists, and the + # NoMethodError it raises masks the real underlying Java exception (see actionpack/lib/action_dispatch/middleware/exception_wrapper.rb:269) + # https://github.com/jruby/jruby/blob/2e078cd889f0a025ff607d9919f3dfdf9bf24390/core/src/main/java/org/jruby/javasupport/ext/JavaLang.java#L221 + # + # This at least allows us to get the message, even though there is no backtrace. + def backtrace_locations + warn "unsupported backtrace_locations access for #{self.inspect}, dumping normal backtrace; and returning empty" + puts self.backtrace + return [] + end + end +end