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

Bad error message when attempting to call a missing constructor

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.5
    • 4.0.0-alpha-1, 3.0.6
    • None
    • None

    Description

      For this class here:

      class Person {
          String name
          Person(String name)  {
              this.name = name
         }
      }
      

      Attempting to construct an instance but supplying the incorrect type yields expected error messages:

      new Person(new Date()) // groovy.lang.GroovyRuntimeException: Could not find matching constructor for: Person(Date)
      new Person(name: new Date()) // groovy.lang.GroovyRuntimeException: failed to invoke constructor: public Person(java.lang.String) with arguments: [] reason: java.lang.IllegalArgumentException: wrong number of arguments
      

      The second is using normal named args which needs a no-arg constructor.

      But when swapping to indy we get:

      new Person(new Date()) // groovy.lang.GroovyRuntimeException: Could not find matching constructor for: Person(Date) [Same]
      new Person(name: new Date()) // java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(String)Person to ()Object [Bad Message]
      

      Attachments

        Activity

          People

            paulk Paul King
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h
                1h