Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/21930#discussion_r206969720
--- Diff: core/src/main/scala/org/apache/spark/util/ClosureCleaner.scala ---
@@ -366,14 +423,26 @@ private[spark] object ClosureCleaner extends Logging {
private[spark] class ReturnStatementInClosureException
extends SparkException("Return statements aren't allowed in Spark
closures")
-private class ReturnStatementFinder extends ClassVisitor(ASM5) {
+private class ReturnStatementFinder(targetMethodName: Option[String] =
None)
+ extends ClassVisitor(ASM5) {
override def visitMethod(access: Int, name: String, desc: String,
sig: String, exceptions: Array[String]): MethodVisitor = {
+
// $anonfun$ covers Java 8 lambdas
if (name.contains("apply") || name.contains("$anonfun$")) {
+ // A method with suffix "$adapted" will be generated in cases like
+ // { _:Int => return; Seq()} but not { _:Int => return; true}
+ // closure passed is $anonfun$t$1$adapted while actual code resides
in $anonfun$s$1
+ // visitor will see only $anonfun$s$1$adapted, so we remove the
suffix, see
+ // https://github.com/scala/scala-dev/issues/109
+ val isTargetMethod = if (targetMethodName.isEmpty) {
--- End diff --
Simplify to `isTargetMethod = targetMethodName.isEmpty || ... || ...`?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]