squito commented on a change in pull request #24239: [SPARK-27121][REPL]
Resolve Scala compiler failure for Java 9+ in REPL
URL: https://github.com/apache/spark/pull/24239#discussion_r270432324
##########
File path: repl/src/test/scala/org/apache/spark/repl/ReplSuite.scala
##########
@@ -34,33 +33,33 @@ class ReplSuite extends SparkFunSuite {
def runInterpreter(master: String, input: String): String = {
val CONF_EXECUTOR_CLASSPATH = "spark.executor.extraClassPath"
- val in = new BufferedReader(new StringReader(input + "\n"))
- val out = new StringWriter()
+
val cl = getClass.getClassLoader
- var paths = new ArrayBuffer[String]
- if (cl.isInstanceOf[URLClassLoader]) {
- val urlLoader = cl.asInstanceOf[URLClassLoader]
- for (url <- urlLoader.getURLs) {
- if (url.getProtocol == "file") {
- paths += url.getFile
- }
- }
- }
- val classpath = paths.map(new
File(_).getAbsolutePath).mkString(File.pathSeparator)
val oldExecutorClasspath = System.getProperty(CONF_EXECUTOR_CLASSPATH)
- System.setProperty(CONF_EXECUTOR_CLASSPATH, classpath)
+ if (oldExecutorClasspath == null) {
+ System.clearProperty(CONF_EXECUTOR_CLASSPATH)
+ } else {
+ System.setProperty(CONF_EXECUTOR_CLASSPATH, oldExecutorClasspath)
+ }
+
+ val classpath = cl match {
+ case urlLoader: URLClassLoader =>
+ val paths = urlLoader.getURLs.filter(_.getProtocol ==
"file").map(_.getFile)
+ val classpath = paths.map(new
File(_).getAbsolutePath).mkString(File.pathSeparator)
+ System.setProperty(CONF_EXECUTOR_CLASSPATH, classpath)
+ classpath
+ case _ => System.getProperty("java.class.path")
Review comment:
the only reason I can think of is the same reason I thought your change was
better -- if somebody directly modifies the class path from within the JVM,
then it won't show up in this system property.
But OTOH, this is our test code, so we control what's happening to the
classpath, and it might as well be the same in java 11 and java 8 -- so I think
this is fine.
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]