rednaxelafx commented on a change in pull request #28463:
URL: https://github.com/apache/spark/pull/28463#discussion_r422063873
##########
File path: core/src/main/scala/org/apache/spark/util/ClosureCleaner.scala
##########
@@ -372,14 +342,64 @@ private[spark] object ClosureCleaner extends Logging {
logDebug(s" +++ closure $func (${func.getClass.getName}) is now cleaned
+++")
} else {
- logDebug(s"Cleaning lambda: ${lambdaFunc.get.getImplMethodName}")
+ val lambdaProxy = maybeIndylambdaProxy.get
+ val implMethodName = lambdaProxy.getImplMethodName
+
+ logDebug(s"Cleaning indylambda closure: $implMethodName")
+
+ // capturing class is the class that declared this lambda
+ val capturingClassName = lambdaProxy.getCapturingClass.replace('/', '.')
+ val classLoader = func.getClass.getClassLoader // this is the safest
option
+ // scalastyle:off classforname
+ val capturingClass = Class.forName(capturingClassName, false,
classLoader)
+ // scalastyle:on classforname
- val captClass =
Utils.classForName(lambdaFunc.get.getCapturingClass.replace('/', '.'),
- initialize = false, noSparkClassLoader = true)
// Fail fast if we detect return statements in closures
- getClassReader(captClass)
- .accept(new
ReturnStatementFinder(Some(lambdaFunc.get.getImplMethodName)), 0)
- logDebug(s" +++ Lambda closure (${lambdaFunc.get.getImplMethodName}) is
now cleaned +++")
+ val capturingClassReader = getClassReader(capturingClass)
+ capturingClassReader.accept(new
ReturnStatementFinder(Option(implMethodName)), 0)
+
+ val isClosureDeclaredInScalaRepl =
capturingClassName.startsWith("$line") &&
+ capturingClassName.endsWith("$iw")
Review comment:
Yes there is a chance of this hacky naming check conflicting with
user-defined class. The likelihood is very low, though. It's hard to be fully
accurate here, unless there's some backdoor trick in NSC that I haven't found
yet. cc @retronym
This check can give both false positives and false negatives:
- it's possible for user code to declare a class name like
`$line12345$read$iw`, and that'd match this check
- it's possible for user to configure the Scala compiler to use a different
prefix for REPL classes (default is `$line`, configurable via
`-Dscala.repl.name.line=XXX`). The name for the import wrapper is fixed at
`$iw` though (see
https://github.com/scala/scala/blob/2.12.x/src/repl/scala/tools/nsc/interpreter/Naming.scala#L71)
I still think this is a tradeoff we'd be okay to make here though.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]