[ https://issues.apache.org/jira/browse/CASSANDRA-11052?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15136352#comment-15136352 ]
Sean Bridges commented on CASSANDRA-11052: ------------------------------------------ What is the purpose of UDFByteCodeVerifier? Non java UDFs don't use UDFByteCodeVerifier, so UDFByteCodeVerifier shouldn't be used to enforce policies like not allowing java.lang.invoke or using the common fork join pool. Javascript UDFs can do both now. It seems all policy/security enforcement should be done using ThreadAwareSecurityManager or some other method common to all UDFs. To stop UDFs using the common fork join pool we could set the system property java.util.concurrent.ForkJoinPool.common.threadFactory to a thread factory that never creates new threads. This would disallow using the common pool for the entire jvm though. I can add tests to make sure ThreadAwareSecurityManager does not allow using java.lang.invoke in a malicious way. I can also add tests that make sure ThreadAwareSecurityManagerudfs doesn't allow creating a new ForkJoinPool. > Cannot use Java 8 lambda expression inside UDF code body > -------------------------------------------------------- > > Key: CASSANDRA-11052 > URL: https://issues.apache.org/jira/browse/CASSANDRA-11052 > Project: Cassandra > Issue Type: Improvement > Components: CQL > Reporter: DOAN DuyHai > Assignee: Robert Stupp > Fix For: 3.x > > Attachments: 11052.patch > > > When creating the following **UDF** using Java 8 lambda syntax > {code:sql} > CREATE FUNCTION IF NOT EXISTS music.udf(state map<text,bigint>, styles > list<text>) > RETURNS NULL ON NULL INPUT > RETURNS map<text,bigint> > LANGUAGE java > AS $$ > styles.forEach((Object o) -> { > String style = (String)o; > if(state.containsKey(style)) { > state.put(style, (Long)state.get(style)+1); > } else { > state.put(style, 1L); > } > }); > > return state; > $$; > {code} > I got the following exception: > {code:java} > Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Could > not compile function 'music.udf' from Java source: > org.apache.cassandra.exceptions.InvalidRequestException: Java source > compilation failed: > Line 2: The type java.util.function.Consumer cannot be resolved. It is > indirectly referenced from required .class files > Line 2: The method forEach(Consumer) from the type Iterable refers to the > missing type Consumer > Line 2: The target type of this expression must be a functional interface > at > com.datastax.driver.core.Responses$Error.asException(Responses.java:136) > at > com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:179) > at > com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:184) > at > com.datastax.driver.core.RequestHandler.access$2500(RequestHandler.java:43) > at > com.datastax.driver.core.RequestHandler$SpeculativeExecution.setFinalResult(RequestHandler.java:798) > at > com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:617) > at > com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1005) > at > com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:928) > at > io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) > at > io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318) > at > io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304) > at > io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266) > at > io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318) > at > io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304) > at > io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) > at > io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318) > at > io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304) > at > io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:276) > at > io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:263) > at > io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318) > at > io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304) > at > io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846) > at > io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131) > at > io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511) > at > io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) > at > io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) > at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) > at > io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112) > ... 1 more > {code} > It looks like the compiler requires importing java.util.Consumer but I have > checked the source code and compiler options already support Java 8 source > code so I'm pretty puzzled here ... > /cc [~snazy] -- This message was sent by Atlassian JIRA (v6.3.4#6332)