Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3799

Bug in passing in Var Args with Inheriters of Abstract classes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6.4
    • 1.6.5, 1.7-beta-2
    • Compiler
    • None

    Description

      I'm running into a problem with Groovy 1.6.4 that looks similar to
      GROOVY-3560. I have the following java interface/classes:

      public interface Foo {

      }

      public class AbstractFoo implements Foo{
      }

      public class ConcreteFoo implements Foo {
      }

      /**Implements Foo, but doesn't inherit from AbstractFoo **/
      public class UnrelatedFoo implements Foo {
      }

      I also have the business java class, FooRunner:

      public class FooRunner {
      private final Foo[] foos;

      public FooRunner(Foo... foos)

      { this.foos = foos; }

      public Foo[] getFoos()

      { return foos; }

      }

      When I try to create a FooRunner from a Groovy script like so:

      FooRunner runner = new FooRunner(new ConcreteFoo(), new UnrelatedFoo());
      println runner.getFoos().length;

      I get:
      Caught: groovy.lang.GroovyRuntimeException: failed to invoke constructor:
      public FooRunner(Foo[]) with arguments: [[ConcreteFoo@a9255c,
      UnrelatedFoo@d3c6a3]]
      reason: java.lang.IllegalArgumentException: argument type mismatch
      at TestFoos.run(TestFoos.groovy:8)

      This does work from Java. If I change my ConcreteFoo to implement Foo
      instead of extending AbstractFoo, it works.

      Attachments

        Activity

          People

            roshandawrani Roshan Dawrani
            deaddowney Adam krieg
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: