JRuby

NativeException should proxy its cause

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 0.9.0
  • Fix Version/s: JRuby 0.9.2
  • Component/s: None
  • Labels:
    None
  • Environment:
    SVN trunk @ rev 2219
  • Number of attachments :
    2

Description

Java exceptions caught by JRuby and wrapped in a NativeException aren't proxied by default. This makes it harder to interoperate with Java libraries and forces the low level API to be exposed in code using the high level API just to inspect the underlying exception. Example:

require 'java'
include_class 'java.io.File' { 'JFile' }

begin
JFile.new(nil)
rescue Exception => e
end

e.cause.some_method_on_java_object # raises NoMethodError even if someMethodOnJava exists

Attaching patch and unit test to fix this on NativeException

  1. NativeException.patch
    25/Aug/06 7:56 AM
    4 kB
    Michael Studman
  2. NativeException.patch
    25/Aug/06 7:55 AM
    4 kB
    Michael Studman

Activity

Hide
Michael Studman added a comment -

Patch causes NativeException.cause() to proxy the returned object by calling JavaUtilities.wrap and passing to it the JavaObject that wraps the real cause object.

There may be a better way to do this but it wasn't clear to me.

Unit test also included.

Show
Michael Studman added a comment - Patch causes NativeException.cause() to proxy the returned object by calling JavaUtilities.wrap and passing to it the JavaObject that wraps the real cause object. There may be a better way to do this but it wasn't clear to me. Unit test also included.
Hide
Michael Studman added a comment -

Added JIRA issue in test case assert.

Show
Michael Studman added a comment - Added JIRA issue in test case assert.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: