From 6ec6f69be2863056c1f10c56406e5a72f2e184cb Mon Sep 17 00:00:00 2001 From: Raphael Jolly Date: Fri, 22 Mar 2013 20:17:14 +0100 Subject: Bypass determination of protection domain when resource is not in a jar --- .../scala/tools/nsc/util/AbstractFileClassLoader.scala | 10 ++++++---- src/reflect/scala/reflect/io/ZipArchive.scala | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/compiler/scala/tools/nsc/util/AbstractFileClassLoader.scala b/src/compiler/scala/tools/nsc/util/AbstractFileClassLoader.scala index e4f879560c..b204c39e9c 100644 --- a/src/compiler/scala/tools/nsc/util/AbstractFileClassLoader.scala +++ b/src/compiler/scala/tools/nsc/util/AbstractFileClassLoader.scala @@ -8,7 +8,6 @@ package util import scala.tools.nsc.io.AbstractFile import java.security.cert.Certificate import java.security.{ ProtectionDomain, CodeSource } -import util.ScalaClassLoader import java.net.{ URL, URLConnection, URLStreamHandler } import scala.collection.{ mutable, immutable } @@ -91,10 +90,13 @@ class AbstractFileClassLoader(val root: AbstractFile, parent: ClassLoader) lazy val protectionDomain = { val cl = Thread.currentThread().getContextClassLoader() val resource = cl.getResource("scala/runtime/package.class") - if (resource == null) null else { + if (resource == null || resource.getProtocol != "jar") null else { val s = resource.getPath - val path = s.substring(0, s.lastIndexOf('!')) - new ProtectionDomain(new CodeSource(new URL(path), null.asInstanceOf[Array[Certificate]]), null, this, null) + val n = s.lastIndexOf('!') + if (n < 0) null else { + val path = s.substring(0, n) + new ProtectionDomain(new CodeSource(new URL(path), null.asInstanceOf[Array[Certificate]]), null, this, null) + } } } diff --git a/src/reflect/scala/reflect/io/ZipArchive.scala b/src/reflect/scala/reflect/io/ZipArchive.scala index 1342fde3c5..11d04538e9 100644 --- a/src/reflect/scala/reflect/io/ZipArchive.scala +++ b/src/reflect/scala/reflect/io/ZipArchive.scala @@ -259,7 +259,11 @@ final class ManifestResources(val url: URL) extends ZipArchive(null) { } def name = path - def path: String = url.getPath() match { case s => s.substring(0, s.lastIndexOf('!')) } + def path: String = { + val s = url.getPath + val n = s.lastIndexOf('!') + s.substring(0, n) + } def input = url.openStream() def lastModified = try url.openConnection().getLastModified() -- cgit v1.2.3