Looks like java exceptions are not wrapped if thrown in toString

Hey guys, if I have a java class that looks like

package bar;
public class Foo {
public void hurl() {
throw new RuntimeException(“I am a RuntimeException.”);
}

@Override
public String toString() {
throw new RuntimeException(“I am a RuntimeException in toString.”);
}
}

and I try to to_s it, it doesn’t get wrapped in a NativeException. This
has
the unfortunate side effect of completely ruining the rails failsafe
response. Below, I create a Foo and then call .hurl and .to_s - you can
see
that the exception from .hurl is wrapped, but the exception from to_s is
the
Java exception. I googled a little and didn’t find a JIRA ticket that
seemed
to address this directly - should there be one?

irb(main):006:0> f = Java::Bar::Foo.new
=> #Java::Bar::Foo:0x2f4c7a98
irb(main):007:0> f.hurl
NativeException: java.lang.RuntimeException: I am a RuntimeException.
from bar/Foo.java:3:in `hurl’
irb(main):008:0> f.to_s
Java::JavaLang::RuntimeException: I am a RuntimeException in toString.
from bar.Foo.toString(Foo.java:5)
from org.jruby.javasupport.JavaObject.to_s(JavaObject.java:175)
from
org.jruby.javasupport.JavaProxyMethods.to_s(JavaProxyMethods.java:53)
from
org.jruby.javasupport.JavaProxyMethods$s_method_0_0$RUBYINVOKER$to_s.call(org/jruby/javasupport/JavaProxyMethods$s_method_0_0$RUBYINVOKER$to_s.gen:65535)
from org.jruby.RubyClass.finvoke(RubyClass.java:602)
from
org.jruby.javasupport.util.RuntimeHelpers.invoke(RuntimeHelpers.java:449)
from org.jruby.RubyBasicObject.asString(RubyBasicObject.java:627)
from org.jruby.ast.EvStrNode.interpret(EvStrNode.java:86)
from org.jruby.ast.DStrNode.appendToString(DStrNode.java:86)
from org.jruby.ast.DStrNode.buildDynamicString(DStrNode.java:76)
from org.jruby.ast.DStrNode.interpret(DStrNode.java:68)
from org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
from org.jruby.ast.RootNode.interpret(RootNode.java:129)
from
org.jruby.evaluator.ASTInterpreter.evalWithBinding(ASTInterpreter.java:98)
from org.jruby.RubyKernel.eval(RubyKernel.java:1045)
from
org.jruby.RubyKernel$s_method_0_3$RUBYFRAMEDINVOKER$eval.call(org/jruby/RubyKernel$s_method_0_3$RUBYFRAMEDINVOKER$eval.gen:65535)
… 103 levels…
from org.jruby.ast.EnsureNode.interpret(EnsureNode.java:96)
from org.jruby.ast.BeginNode.interpret(BeginNode.java:83)
from org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
from org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
from
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:180)
from
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:174)
from
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:309)
from
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:148)
from Users.najati_imam.javabin.jruby.bin.jirb.file(jirb:13)
from Users.najati_imam.javabin.jruby.bin.jirb.load(jirb)
from org.jruby.Ruby.runScript(Ruby.java:690)
from org.jruby.Ruby.runNormally(Ruby.java:573)
from org.jruby.Ruby.runFromMain(Ruby.java:416)
from org.jruby.Main.run(Main.java:286)
from org.jruby.Main.run(Main.java:128)
from org.jruby.Main.main(Main.java:97)irb(main):009:0>