Github user JoshRosen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4935#discussion_r25987271
  
    --- Diff: 
repl/src/main/scala/org/apache/spark/repl/ExecutorClassLoader.scala ---
    @@ -71,27 +72,64 @@ class ExecutorClassLoader(conf: SparkConf, classUri: 
String, parent: ClassLoader
         }
       }
     
    +  private def getClassFileInputStreamFromHttpServer(pathInDirectory: 
String): InputStream = {
    +    val url: URL = if 
(SparkEnv.get.securityManager.isAuthenticationEnabled()) {
    +      val uri = new URI(classUri + "/" + urlEncode(pathInDirectory))
    +      Utils.constructURIForAuthentication(uri, 
SparkEnv.get.securityManager).toURL
    +    } else {
    +      new URL(classUri + "/" + urlEncode(pathInDirectory))
    +    }
    +    val connection = url.openConnection().asInstanceOf[HttpURLConnection]
    +    if (connection.asInstanceOf[HttpURLConnection].getResponseCode != 200) 
{
    +      connection.disconnect()
    +      throw new ClassNotFoundException(s"Class file not found at URL $url")
    +    } else {
    +      connection.getInputStream
    +    }
    +  }
    +
    +  private def getClassFileInputStreamFromFileSystem(pathInDirectory: 
String): InputStream = {
    +    val path = new Path(directory, pathInDirectory)
    +    if (fileSystem.exists(path)) {
    +      fileSystem.open(path)
    +    } else {
    +      throw new ClassNotFoundException(s"Class file not found at path 
$path")
    +    }
    +  }
    +
       def findClassLocally(name: String): Option[Class[_]] = {
    +    val pathInDirectory = name.replace('.', '/') + ".class"
    +    var inputStream: InputStream = null
         try {
    -      val pathInDirectory = name.replace('.', '/') + ".class"
    -      val inputStream = {
    +      inputStream = {
             if (fileSystem != null) {
    -          fileSystem.open(new Path(directory, pathInDirectory))
    +          getClassFileInputStreamFromFileSystem(pathInDirectory)
             } else {
    -          if (SparkEnv.get.securityManager.isAuthenticationEnabled()) {
    -            val uri = new URI(classUri + "/" + urlEncode(pathInDirectory))
    -            val newuri = Utils.constructURIForAuthentication(uri, 
SparkEnv.get.securityManager)
    -            newuri.toURL().openStream()
    -          } else {
    -            new URL(classUri + "/" + 
urlEncode(pathInDirectory)).openStream()
    --- End diff --
    
    If a class couldn't be found, then this would throw `FileNotFoundException`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to