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

wrong method override is chosen

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.5.4
    • 1.5.5, 1.6-beta-1
    • None
    • None

    Description

      Several people using Grails have noticed that in order to use Spring's JavaMailSender (http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/mail/javamail/JavaMailSender.html), you need to cast the message in order for send() to find the correct override. I dug into the code and send(MimeMessagePreparator[]) is the chosen method even though the message object doesn't implement MimeMessagePreparator, resulting in IllegalArgumentException on invoke.

      The bug is in org.codehaus.groovy.reflection.ParameterTypes.isValidMethod(), line 253 (in Groovy 1.5.4) where it calls "MetaClassHelper.isAssignableFrom(clazz, arguments[paramMinus1].getComponentType())" - here clazz is MimeMessagePreparator and arguments[paramMinus1] is a subclass of MimeMessage. Since it's not an array, getComponentType() returns null and MetaClassHelper.isAssignableFrom() returns true, allowing the invalid method to be considered.

      Then in groovy.lang.MetaClassImpl.chooseMostSpecificParams() the invalid method gets a lower distance (536870912, just the penalty for varargs) than the correct method's (85899345920), so it wins.

      Although this was seen in Grails apps, I was able to distill the problem down and have attached a JUnit test that shows the problem.

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            blackdrag Jochen Theodorou
            burtbeckwith Burt Beckwith
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment