JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-3622

newInstance and getDeclaredConstructor fail to respect class overridden in JRuby

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: JRuby 1.2
    • Fix Version/s: None
    • Component/s: Java Integration
    • Labels:
      None
    • Environment:
      Java 6 / OS X 10.5
    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      When a Java class is inherited from in Ruby, passing it to a Java method that uses newInstance or getDeclaredConstructor results in an object that has none of the overridden methods. Essentially, it appears to instantiate its superclass.

      If object instantiation occurs within Ruby, passing the object to a Java method results in the correct behavior.

      There is a failing test case included.

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        Have you tried this against JRuby 1.3RC1? I'm a little swamped at the moment, but please give it another shot. I think there may have been a related bug fixed in the 1.3 cycle.

        Show
        Charles Oliver Nutter added a comment - Have you tried this against JRuby 1.3RC1? I'm a little swamped at the moment, but please give it another shot. I think there may have been a related bug fixed in the 1.3 cycle.
        Hide
        Stephen Judkins added a comment -

        Running the test in JRuby 1.3RC1 resulted in the same failures.

        Show
        Stephen Judkins added a comment - Running the test in JRuby 1.3RC1 resulted in the same failures.
        Hide
        Charles Oliver Nutter added a comment -

        This should be fixed with the upcoming "new JI" "real class" support. The class created will actually be instantiable and reflectable from the Java side of things.

        Show
        Charles Oliver Nutter added a comment - This should be fixed with the upcoming "new JI" "real class" support. The class created will actually be instantiable and reflectable from the Java side of things.
        Hide
        Charles Oliver Nutter added a comment -

        This is unfortunately not going to get into 1.5. I'm moving the target release to 1.6.

        The problem is that in order to provide class extension, we still need objects passing through Ruby space to implement IRubyObject. Currently, the simplest way to do that is to have them extend RubyObject, but that means we can't extend anything else. So we create a second class...a "double"...that's instantiated when the Ruby object is instantiated, and the two live life together.

        This bug is caused because the "double" has special constructors and behavior that make it behave as a double, and as a result it can't be instantiated directly. Instantiation is driven from the Ruby side, with the Ruby object constructed first and the Java double constructed as a tagalong. Going the other direction with this model is not currently possible.

        There is, however, some hope. JRuby master has some prototype code that actually makes a new class that both extends the one you specify and implements IRubyObject. It does not yet have all the features (or all the required behavior) present in the old "doubled" version, but it's coming along. If you'd be interested in trying it out, you can set the Java property jruby.ji.newStyleExtension=true, which will make all class extension use the new logic. It's early, but it's coming along.

        Show
        Charles Oliver Nutter added a comment - This is unfortunately not going to get into 1.5. I'm moving the target release to 1.6. The problem is that in order to provide class extension, we still need objects passing through Ruby space to implement IRubyObject. Currently, the simplest way to do that is to have them extend RubyObject, but that means we can't extend anything else. So we create a second class...a "double"...that's instantiated when the Ruby object is instantiated, and the two live life together. This bug is caused because the "double" has special constructors and behavior that make it behave as a double, and as a result it can't be instantiated directly. Instantiation is driven from the Ruby side, with the Ruby object constructed first and the Java double constructed as a tagalong. Going the other direction with this model is not currently possible. There is, however, some hope. JRuby master has some prototype code that actually makes a new class that both extends the one you specify and implements IRubyObject. It does not yet have all the features (or all the required behavior) present in the old "doubled" version, but it's coming along. If you'd be interested in trying it out, you can set the Java property jruby.ji.newStyleExtension=true, which will make all class extension use the new logic. It's early, but it's coming along.
        Hide
        Charles Oliver Nutter added a comment -

        Too late in cycle for anything drastic. 1.7 or not at all?

        Show
        Charles Oliver Nutter added a comment - Too late in cycle for anything drastic. 1.7 or not at all?

          People

          • Assignee:
            Unassigned
            Reporter:
            Stephen Judkins
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: