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

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.5.4
    • Fix Version/s: 1.5.5, 1.6-beta-1
    • Component/s: None
    • Labels:
      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

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              burtbeckwith Burt Beckwith

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment