Raising java exceptions from ruby causes TypeError
---------------------------------------------------
Key: JRUBY-1615
URL: http://jira.codehaus.org/browse/JRUBY-1615
Project: JRuby
Issue Type: Bug
Components: Java Integration
Affects Versions: JRuby 1.1b1
Reporter: simon jenkins
The following example will fail with a TypeError, not the expected error which
is the raised java RutimeException
require 'java'
raise java.lang.RuntimeException.new('something went wrong')
This becomes an issue when integrating java and ruby, for example when writting
rspec tests for java classes it is difficult to test exception scenarios. This
will also likely be a problem when calling ruby components from java code as
the returned exceptions from the ruby code will not be the 'expected' java
exceptions. Likely exposing to the calling class the fact the implementation
is ruby. This might not be desirable depending on the case.
The cause of the issue is the RubyKernel class in the raise method checks to
see whether the argument is either a String or responds to the "exception"
message. Java RuntimeException will not, as such a TypeError is raised.
Patching the RubyKernel class to check if the argument to the raise method has
an "@java_object" and that the @java_object has a value which is of type
RuntimeException and raising that instead resolves the issue.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email