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

JRuby subclass cannot call super with arguments if parent constructor is varargs

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: JRuby 1.6.7
    • Fix Version/s: None
    • Component/s: Java Integration
    • Labels:
      None
    • Environment:
      MacOS 10.7.3
    • Number of attachments :
      1

      Description

      I subclass a Java class that has a varargs constructor in JRuby, the JRuby class attempts to call super(a,b) to invoke the superclasses constructor and this fails with:

      ArgumentError: wrong number of arguments for constructor
        initialize at varargsctor.rb:6
            (root) at varargsctor.rb:11
      

      Invoking super(nil) works, but super() and super(a,b) fail.
      Sample Java class and JRuby subclass attached.

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        Good find! Investigating.

        Show
        Charles Oliver Nutter added a comment - Good find! Investigating.
        Hide
        Charles Oliver Nutter added a comment -

        Ok, this is a known difference in the logic for extending a class in Ruby. This logic is slated to be rewritten for JRuby 1.7, but likely not before the preview release for JRubyConf.

        The problem here is that superclass constructor invocation proceeds along a different code path for extended classes than it does for constructing a normal Java object from Ruby. The latter is the path which has varargs support.

        I will mark this as a 1.7 bug. In the interim, you can cache an empty String array like EMPTY_STR_ARY = [].to_java(:string) and pass that to varargs String super call.

        Show
        Charles Oliver Nutter added a comment - Ok, this is a known difference in the logic for extending a class in Ruby. This logic is slated to be rewritten for JRuby 1.7, but likely not before the preview release for JRubyConf. The problem here is that superclass constructor invocation proceeds along a different code path for extended classes than it does for constructing a normal Java object from Ruby. The latter is the path which has varargs support. I will mark this as a 1.7 bug. In the interim, you can cache an empty String array like EMPTY_STR_ARY = [].to_java(:string) and pass that to varargs String super call.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Andrew Wason
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: