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
-
Testcase included:yes
-
Number of attachments :
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
| This issue relates to: | ||||
| GROOVY-2698 | Method dispatch with overloaded methods for Java types doesn't choose the most specific method |
|
|
|
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