-
-
Notifications
You must be signed in to change notification settings - Fork 922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ruby exceptions passing through Java Integration and back remain wrapped #1839
Comments
I think it is because the interpreter (in this debug output below) receives a NativeException and it only unwraps RaiseExceptions. This is debug output from a short test snippet to reproduce that error. We should chat about whether NativeExceptions receive special handling or if this is something that requires changing in JI ... ... |
NativeException should almost never happen. We got rid of those in 1.6 I think. We need to figure out who's creating this NativeException and fix it on that end, I suppose. |
Oh, it is gone? Then IRRuntimeHelpers has stale code :) ... See https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java#L297 ... and on line 304, it sets $! to that. |
Ok, sorry, it's not completely gone. For backward compatibility, if someone rescues NativeException and we receive a Java exception, then we wrap it before we give it to them. But otherwise we should be propagating the exception as-is and not wrapping it. |
There seems to be couple things going on. (1) JI code somewhere is setting (2) In addition, in IRRuntimeHelpers code above, in some scenarios, looks like This is probably best fixed by one of you since you understand JI and I haven't delved into that part of JRuby yet, but happy to chat on irc/im about any of this. |
An update on what is going on based on some debugging. https://gist.githubusercontent.com/subbuss/d29d501f0cadd8b92a39/raw/993c2a9589bec27b57a192542578bf6b7986e92f/gistfile1.txt shows you what is going on. When the raise in the ruby code executes, $! is correctly set to the RaiseException object. But, when the exception propagates into the JI code, JI catches the exception and does a stack-trace rewrite before rethrowing it. It uses Helpers.rewriteStackTraceAndThrow for this. Here is the code for that method:
So, this creates a nativeException -- but RaiseException code unconditionally sets |
Isn't this fixed now? |
This has to be fixed. We'd see a lot more issues with our ruby kernel or the JI specs if it wasn't. |
This is either a problem with JI (my area) or IR (@enebo or @subbuss).
It appears that exceptions raised by Ruby code called by Java code called through Java integration (a Ruby exception that passes through a JI call on its way out) remain wrapped and are presented to rescue blocks as the wrapped RaiseException rather than the contained Ruby exception.
This happens regardless of JIT status, and since I have not done anything with JI and exceptions recently I suspect this is a flaw in how IR handles unwrapping exceptions for rescue.
The text was updated successfully, but these errors were encountered: