groovy

wrong method override is chosen

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.5.4
  • Fix Version/s: 1.5.5, 1.6-beta-1
  • Component/s: None
  • Labels:
    None
  • Testcase included:
    yes
  • Number of attachments :
    1

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.

Issue Links

Activity

Hide
Burt Beckwith added a comment -

Sorry, I should have checked the open issues before submitting. This is a duplicate of http://jira.codehaus.org/browse/GROOVY-2658 and http://jira.codehaus.org/browse/GROOVY-2698

Show
Burt Beckwith added a comment - Sorry, I should have checked the open issues before submitting. This is a duplicate of http://jira.codehaus.org/browse/GROOVY-2658 and http://jira.codehaus.org/browse/GROOVY-2698
Hide
blackdrag blackdrag added a comment -

this issue is no duplicate, the fix for this issue does not fix the other two.. anyway, this one is fixed now

Show
blackdrag blackdrag added a comment - this issue is no duplicate, the fix for this issue does not fix the other two.. anyway, this one is fixed now

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: