Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.7.0.pre1
    • Fix Version/s: JRuby 1.7.0.pre2
    • Component/s: Java Integration
    • Labels:
      None
    • Environment:
      jruby 1.7.0.preview2.dev (ruby-1.9.3-p203) (2012-08-01 5fe8b45) (Java HotSpot(TM) Server VM 1.6.0_32) [linux-i386-java]
    • Number of attachments :
      1

      Description

      I'm really sorry as this is going to be pretty vague, I tried to narrow things down but have been only able to spot the failure while running with RSpec (2.11 version seems to not matter that much as far as I tried).

      seems as a regression to me as things work well with jruby 1.6.7 (1.8 and 1.9 as well) but not with jruby-head, here's a piece of code :

      require 'rhino'
      
      begin 
        raise Rhino::Ruby::Exception.new(42)
      rescue java.lang.Exception => e
        puts "rescued exception class name: #{e.class.name}"
        puts "is is a Rhino::Ruby::Exception ? #{e.is_a?(Rhino::Ruby::Exception)}"
      end
      

      now pasting this into an irb seems to work but not when in a spec, please try running the following :

      git clone git://github.com/cowboyd/therubyrhino.git
      bundle install
      bundle exec rspec spec/rhino/ruby_spec.rb -e Exception
      

      should end up with a failure :

      
        1) Rhino::Ruby::Exception outcomes as ruby errors in function calls
           Failure/Error: e.should be_a(Rhino::Ruby::Exception)
             expected org.jruby.proxy.org.mozilla.javascript.JavaScriptException$Proxy2: [object Fixnum] to be a kind of Rhino::Ruby::Exception
           # ./spec/rhino/ruby_spec.rb:413:in `(root)'
      

      spec is a little more complicated but replacing the highlighted lines with the above code fails as well (note again it passes all fine with 1.6.7) :

          begin
            raise Rhino::Ruby::Exception.new(42)
          rescue java.lang.Exception => e
            e.should be_a(Rhino::Ruby::Exception)
            # ...
      
      1. test.rb
        0.1 kB
        kristian meier

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        A simple case appears to work correctly:

        system ~/projects/jruby $ jruby -rjava -e "class MyException < java.lang.Exception; end; begin; raise MyException.new; rescue java.lang.Exception => e; p e; p e.class; p e.is_a?(MyException); end"
        org.jruby.proxy.java.lang.Exception$Proxy0
        MyException
        true
        
        Show
        Charles Oliver Nutter added a comment - A simple case appears to work correctly: system ~/projects/jruby $ jruby -rjava -e "class MyException < java.lang.Exception; end; begin; raise MyException.new; rescue java.lang.Exception => e; p e; p e.class; p e.is_a?(MyException); end" org.jruby.proxy.java.lang.Exception$Proxy0 MyException true
        Hide
        Charles Oliver Nutter added a comment -

        Ah-ha...the interpreter is doing it wrong:

        system ~/projects/jruby $ jruby -X-C -rjava -e "class MyException < java.lang.Exception; end; begin; raise MyException.new; rescue java.lang.Exception => e; p e; p e.class; p e.is_a?(MyException); end"
        org.jruby.proxy.java.lang.Exception$Proxy0
        #<Class:0xfb51005>
        false
        

        Fix coming.

        Show
        Charles Oliver Nutter added a comment - Ah-ha...the interpreter is doing it wrong: system ~/projects/jruby $ jruby -X-C -rjava -e "class MyException < java.lang.Exception; end; begin; raise MyException.new; rescue java.lang.Exception => e; p e; p e.class; p e.is_a?(MyException); end" org.jruby.proxy.java.lang.Exception$Proxy0 #<Class:0xfb51005> false Fix coming.
        Hide
        Charles Oliver Nutter added a comment -

        In just under the wire!

        commit 9b1cc7b25e3b4e56f667c04917f118a0eed98469
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Fri Aug 3 11:32:14 2012 -0500
        
            Fix JRUBY-6812: 1.7 regression handling Java exceptions
            
            We were shortcutting the logic to convert the rescued exception
            into its appropriate Ruby nature. Specifically, we went straight
            to wrapping it with a proxy object rather than checking if it was
            a Ruby subclass that already had an object associated with it.
            
            The fix was to go through appropriate channels, specifically
            JavaUtil.convertJavaToUsableRubyObject, which checks for Ruby
            subclasses before proceeding to wrap blindly.
            
            This only affected the interpreter. Compiled code was already
            doing the right thing.
        
        :100644 100644 38ab2d0... 3748045... M	spec/java_integration/exceptions/rescue_spec.rb
        :100644 100644 703fde43.. 730159d... M	src/org/jruby/ast/RescueNode.java
        
        Show
        Charles Oliver Nutter added a comment - In just under the wire! commit 9b1cc7b25e3b4e56f667c04917f118a0eed98469 Author: Charles Oliver Nutter <headius@headius.com> Date: Fri Aug 3 11:32:14 2012 -0500 Fix JRUBY-6812: 1.7 regression handling Java exceptions We were shortcutting the logic to convert the rescued exception into its appropriate Ruby nature. Specifically, we went straight to wrapping it with a proxy object rather than checking if it was a Ruby subclass that already had an object associated with it. The fix was to go through appropriate channels, specifically JavaUtil.convertJavaToUsableRubyObject, which checks for Ruby subclasses before proceeding to wrap blindly. This only affected the interpreter. Compiled code was already doing the right thing. :100644 100644 38ab2d0... 3748045... M spec/java_integration/exceptions/rescue_spec.rb :100644 100644 703fde43.. 730159d... M src/org/jruby/ast/RescueNode.java
        Hide
        Karol Bucek added a comment -

        works perfectly, thanks Charlie !
        therubyrhino now 1.7 compatible (as far as the specs go)

        Show
        Karol Bucek added a comment - works perfectly, thanks Charlie ! therubyrhino now 1.7 compatible (as far as the specs go)
        Hide
        Charles Oliver Nutter added a comment -

        Great, thanks!

        FYI, we generally don't close bugs until they go out in a release. Not a big deal this time, but for future reference.

        Show
        Charles Oliver Nutter added a comment - Great, thanks! FYI, we generally don't close bugs until they go out in a release. Not a big deal this time, but for future reference.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Karol Bucek
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: