groovy
  1. groovy
  2. GROOVY-3878

Can't call Java varargs method when it's mixed in to toplevel

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6.5, 1.7-beta-2
    • Fix Version/s: 1.6.6, 1.7-rc-1
    • Component/s: None
    • Labels:
      None
    • Environment:
      Java 1.5, OS X Leopard.
    • Number of attachments :
      4

      Description

      Take this Java class:

      Dsl.java
      public class Dsl {
          public static void novarargs(java.util.List s) {
              System.out.println("novarargs ok");
          }
      
          public static void varargs(Object... s) {
              System.out.println("varargs ok");
          }
      }
      

      Run it with Groovy:

      UseDsl.groovy
      this.metaClass.mixin(Dsl)
      
      Dsl.novarargs(["a", "b"])
      novarargs(["a", "b"])
      
      Dsl.varargs("a", "b")
      varargs("a", "b")    // fails here
      

      The last one fails:

      javac Dsl.java && groovy UseDsl.groovy 
      
      Caught: java.lang.IllegalArgumentException: wrong number of arguments
      	at UseDsl.run(UseDsl.groovy:7)
      
      1. 3678_v17x.txt
        0.6 kB
        Roshan Dawrani
      2. groovy3878_mixin_varargs.patch
        1 kB
        Paul King
      3. NewDsl.java
        0.7 kB
        Roshan Dawrani
      4. TestNewDsl.groovy
        0.8 kB
        Roshan Dawrani

        Activity

        Hide
        Roshan Dawrani added a comment -

        Attaching an alternative patch for review and its test files.

        Test can be run as:

        javac NewDsl.java && groovy TestNewDsl.groovy
        
        Show
        Roshan Dawrani added a comment - Attaching an alternative patch for review and its test files. Test can be run as: javac NewDsl.java && groovy TestNewDsl.groovy
        Hide
        Roshan Dawrani added a comment -

        Attaching a slightly easier version of TestNewDsl.groovy for review.

        Show
        Roshan Dawrani added a comment - Attaching a slightly easier version of TestNewDsl.groovy for review.
        Hide
        blackdrag blackdrag added a comment -

        looks good to me

        Show
        blackdrag blackdrag added a comment - looks good to me
        Hide
        Paul King added a comment -

        I had a similar solution to Roshan's though I had to do a pre-emptive call to method.getParameterTypes() in order for the testcase that I added to pass. The only difference is that my testcase uses a Groovy mixin class and is located in the same script. It would be nice to push that logic somewhere else but I haven't had time yet to investigate.

        Show
        Paul King added a comment - I had a similar solution to Roshan's though I had to do a pre-emptive call to method.getParameterTypes() in order for the testcase that I added to pass. The only difference is that my testcase uses a Groovy mixin class and is located in the same script. It would be nice to push that logic somewhere else but I haven't had time yet to investigate.
        Hide
        Aslak Helles°y added a comment -

        Thanks for fixing this guys!

        Show
        Aslak Helles°y added a comment - Thanks for fixing this guys!

          People

          • Assignee:
            Paul King
            Reporter:
            Aslak Helles°y
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: