I have an odd issue with method closures. I'm on Groovy 2.4.12 in dynamic mode 
and I'm trying to transform data to a map for a webservice. I don't know if I'm 
using wrong syntax or if it's a Groovy bug.

This line of code results in MissingMethodException:
response.pa.opportunityQuotes       = 
pa.opportunityQuotes.collect(this.&mapOpportunityQuote)

pa.opportunityQuotes returns List<Quote> and mapOpportunityQuote is an instance 
method taking a Quote and returning a Map. The method containing above line is 
in AbstractPAService but at runtime "this" is a Service class extends 
AbstractPAService. The MissingMethodException says there's no 
Service.mapOpportunityQuote method, which is technically true as the method is 
on AbstractPAService. Whether mapOpportunityQuote is protected or private does 
not matter.

This line of code does work, which makes me think I hit a Groovy bug and not 
something in my code:


response.pa.opportunityQuotes       = pa.opportunityQuotes.collect { 
((AbstractPAService) owner).mapOpportunityQuote(it) }

The usage of owner and downcasting it to AbstractPAService should be redundant.

I want the MethodClosure created by this.&mapOpportunityQuote to resolve the 
method on AbstractPAService class, not on Service class that extends it. 
Although, I'm confused why making mapOpportunityQuote protected did not 
workaround the issue.

Jason Winnebeck
Software Engineer III Contractor - IT Software Development | Windstream
600 Willowbrook Office Park, Rochester, NY 14450
jason.winneb...@windstream.com<mailto:jason.winneb...@windstream.com> | 
windstreambusiness.com
o: 585.794-4585

This email message and any attachments are for the sole use of the intended 
recipient(s). Any unauthorized review, use, disclosure or distribution is 
prohibited. If you are not the intended recipient, please contact the sender by 
reply email and destroy all copies of the original message and any attachments.

Reply via email to