History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-1300
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Charles Oliver Nutter
Reporter: Jani
Votes: 1
Watchers: 5
Operations

If you were logged in you would be able to see more operations.
JRuby

Masquerading of native Java exceptions

Created: 30/Aug/07 11:24 AM   Updated: 10/Sep/08 06:44 PM
Component/s: Java Integration
Affects Version/s: JRuby 1.0.0
Fix Version/s: JRuby 1.1.4

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive TestCode.zip (2 kb)

Environment: Windows Java /1.6

Testcase included: yes


 Description  « Hide
Some Java frameworks define a standard handling for exceptions. In some situations this will be broken by using JRuby.

For instance a Framework could define a Java callback handler interface. This call back handler interface can be implemented by a JRuby class. If the framework implements a specific handling by catching specific exception, the contract between handler and framework fails. Java exceptions, which will be thrown (indirectly) by the handler are nested into a JRuby org.jruby.exceptions.RaiseException by the JRuby runtime. Instead of catching the native Java exception the framework will catch a JRuby exception.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Charles Oliver Nutter - 19/Oct/07 10:17 PM
We need to unwrap Java exceptions on the way back out into Java code. We can't reliably do this for direct calls from Java into JRuby objects, but we should be able to do it for any cases where we extend/implement/override methods; those method implementations should wrap the call into Ruby with appropriate code to catch RaiseException and unwrap it if it contains a normal Java exception (i.e. if it's a NativeException to Ruby).

A better solution will come long-term with a move to "lightweights", where we will have no wrappers at all.


Charles Oliver Nutter - 15/Feb/08 12:57 PM
Punting issues from 1.1 RC2 to 1.1 final.

Charles Oliver Nutter - 17/Mar/08 12:03 PM
This is Java integration related and nontrivial...we're not going to have it ready for 1.1.

Thomas Smith - 21/Aug/08 05:38 PM
I encountered this with a real framework and implementation need. Do any workarounds exist?

I did not expect it to work, but I tried:

begin
...
rescue NativeException => e
raise e.cause
end

The calling Java code still sees the thrown exception as an org.jruby.exceptions.RaiseException, which makes sense because you just raised an exception out of Ruby code.


Thomas Smith - 23/Aug/08 12:15 AM
Adding link to documented impact and analysis with real framework and implementation need:

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=os_core_pde;action=display;num=1219396204;start=0#2

Can also use this to validate fix in addition to originally attached test case.


Charles Oliver Nutter - 26/Aug/08 03:18 PM
This is improved lately by allowing Ruby code to catch and raise Java exceptions without wrapping them. However the unwrapping when coming out of JRuby API calls or out of scripting interfaces (BSF, javax.script) is more problematic; since on the Java side of things those APIs don't say they're throwing those exception types, code calling them can't catch them. The best we could do would be to put the actual Java exception inside the API's wrapper exception. I'm going to call this one fixed, since there's various workarounds, recent 1.1 releases have a lot better support for raising and rescuing Java exceptions directly, and future JRuby will certainly have no distinction between Ruby exceptions and Java exceptions.