groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paolo Di Tommaso <paolo.ditomm...@gmail.com>
Subject NPE with new Macro feature
Date Mon, 16 Jul 2018 06:32:50 GMT
Dear all,

I'mv trying to use the new `macro` feature to execute a class method call
expression using an executor service.

I've tried:


    private BlockStatement wrap(MethodCallExpression mce) {
        return macro(true,{

            def executor =
java.util.concurrent.Executors.newCachedThreadPool()
            def list = new ArrayList(1)
            list.add( { return $v{ mce } } as Callable )
            def result = executor.invokeAll(list)
            return result.get(0).get()

        })
    }


and


    private BlockStatement wrap(MethodCallExpression mce) {
        return macro(true,{

            def task = new java.util.concurrent.Callable<Object>() {
                @Override
                Object call() throws Exception { return $v{ mce } }
            }

            ExecutorService executor =
java.util.concurrent.Executors.newCachedThreadPool()
            def list = new ArrayList(1)
            list.add(task)
            def result = executor.invokeAll(list)
            return result.get(0).get()

        })
    }


However none of them work. The first return a NPE during compilation and
the second reports:

Groovyc: [Static type checking] - Cannot find matching method
nextflow.ast.ProxyImpl$1#$v(groovy.lang.Closure). Please check if the
declared type is correct and if the method exists.

(using CompileDynamic I got a NPE error one more time)


What I'm missing? is it possible to handle this use case with an ast macro ?



p

Mime
View raw message