[
https://issues.apache.org/jira/browse/GROOVY-9656?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149166#comment-18149166
]
Daniel Sun commented on GROOVY-9656:
------------------------------------
Fixed on master; added a regression test in
a757af0031465e2b60418d795f69b497079f0764
(https://github.com/apache/groovy/commit/a757af0031465e2b60418d795f69b497079f0764).
> ExecutorService as a @Delegate calls the Runnable submit instead of the
> Callable one
> ------------------------------------------------------------------------------------
>
> Key: GROOVY-9656
> URL: https://issues.apache.org/jira/browse/GROOVY-9656
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 3.0.5, 2.5.13
> Reporter: Tim Yates
> Assignee: Daniel Sun
> Priority: Major
> Fix For: 7.0.0-alpha-1
>
>
> When {{ExecutorService}} is used with the {{@Delegate}} annotation, then
> casting a Closure to a {{Callable}} doesn't seem to call the correct method
> (we suspect it's calling the {{Runnable}} method)
>
> Given the following script:
> {code:java}
> import java.util.concurrent.Callable
> import java.util.concurrent.ExecutorService
> import java.util.concurrent.Executors
> import java.util.concurrent.Future
> import java.util.concurrent.TimeUnit
> class MyService {
> @Delegate ExecutorService delegateExecutorService =
> Executors.newCachedThreadPool()
> }
> def test(ExecutorService s) {
> println s.submit { 42 }.get()
> println s.submit([call: { 42 }] as Callable).get()
> println s.submit({ 42 } as Callable).get()
> s.shutdownNow()
> }
> println "Delegated ExecutorService"
> test(new MyService())
> println()
> println "Actual ExecutorService"
> test(Executors.newCachedThreadPool())
> {code}
> The output is:
> {code}
> Delegated ExecutorService
> null
> 42
> null
> Actual ExecutorService
> null
> 42
> 42
> {code}
> Whereas I was expecting the first delegated result to be the same as calling
> the actual executor service...
> Apologies if this is a dupe, or documented, I did try and look, but to no
> avail
> Cheers
> Tim
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)