diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-10-23 05:48:23 -0700 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-10-23 05:48:23 -0700 |
commit | daa86942900ecfa2e48dfbb31aa50fe5d56ee937 (patch) | |
tree | 9640caf37855aab5c772dd3f86bb72e2ddbb14a4 | |
parent | 9c1021270ab55f31dd1c680ed51b9aed4c531e1a (diff) | |
parent | e350bd2cbc0183d5bedbdb8fd4101f93da30483b (diff) | |
download | scala-daa86942900ecfa2e48dfbb31aa50fe5d56ee937.tar.gz scala-daa86942900ecfa2e48dfbb31aa50fe5d56ee937.tar.bz2 scala-daa86942900ecfa2e48dfbb31aa50fe5d56ee937.zip |
Merge pull request #3053 from som-snytt/issue/6026-AFCL-findresource
[nomaster] SI-6026 backport getResource bug fix
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala | 16 | ||||
-rw-r--r-- | test/disabled/run/t6026.check | 9 | ||||
-rw-r--r-- | test/disabled/run/t6026.scala | 9 |
3 files changed, 33 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala b/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala index 638bca8a72..59508fa951 100644 --- a/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala +++ b/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala @@ -7,7 +7,7 @@ package interpreter import scala.tools.nsc.io.{ File, AbstractFile } import util.ScalaClassLoader -import java.net.URL +import java.net.{ URL, URLConnection, URLStreamHandler } import scala.collection.{ mutable, immutable } /** @@ -55,10 +55,24 @@ class AbstractFileClassLoader(val root: AbstractFile, parent: ClassLoader) return file } + // parent delegation in JCL uses getResource; so either add parent.getResAsStream + // or implement findResource, which we do here as a study in scarlet (my complexion + // after looking at CLs and URLs) + override def findResource(name: String): URL = findAbstractFile(name) match { + case null => null + case file => new URL(null, "repldir:" + file.path, new URLStreamHandler { + override def openConnection(url: URL): URLConnection = new URLConnection(url) { + override def connect() { } + override def getInputStream = file.input + } + }) + } + // this inverts delegation order: super.getResAsStr calls parent.getRes if we fail override def getResourceAsStream(name: String) = findAbstractFile(name) match { case null => super.getResourceAsStream(name) case file => file.input } + // ScalaClassLoader.classBytes uses getResAsStream, so we'll try again before delegating override def classBytes(name: String): Array[Byte] = findAbstractFile(name) match { case null => super.classBytes(name) case file => file.toByteArray diff --git a/test/disabled/run/t6026.check b/test/disabled/run/t6026.check new file mode 100644 index 0000000000..779bb3ace5 --- /dev/null +++ b/test/disabled/run/t6026.check @@ -0,0 +1,9 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> class Foo +defined class Foo + +scala> :javap Foo +Compiled from "<console>"public class Foo extends java.lang.Object{ public Foo();} +scala> diff --git a/test/disabled/run/t6026.scala b/test/disabled/run/t6026.scala new file mode 100644 index 0000000000..bee27bc72a --- /dev/null +++ b/test/disabled/run/t6026.scala @@ -0,0 +1,9 @@ + +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + override def code = +"""|class Foo + |:javap Foo + |""".stripMargin +} |