Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
1.5.4
-
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
Attachments
Issue Links
- relates to
-
GROOVY-2698 Method dispatch with overloaded methods for Java types doesn't choose the most specific method
- Closed