diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/plugins/ServiceLoaderLite.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/plugins/ServiceLoaderLite.kt index 807a6ed40ef..fa30fdd6489 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/plugins/ServiceLoaderLite.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/plugins/ServiceLoaderLite.kt @@ -11,7 +11,10 @@ import java.lang.Character.isJavaIdentifierPart import java.lang.Character.isJavaIdentifierStart import java.lang.IllegalArgumentException import java.lang.RuntimeException +import java.lang.UnsupportedOperationException import java.net.URLClassLoader +import java.nio.file.FileSystemNotFoundException +import java.nio.file.Paths import java.util.zip.ZipFile /** @@ -32,9 +35,13 @@ object ServiceLoaderLite { */ fun loadImplementations(service: Class, classLoader: URLClassLoader): List { val files = classLoader.urLs.map { url -> - if (url.protocol.toLowerCase() != "file") throw IllegalArgumentException("Only local files are supported, got $url") - val path = url.path.takeIf { it.isNotEmpty() } ?: throw IllegalArgumentException("Path is empty for $url") - File(path) + try { + Paths.get(url.toURI()).toFile() + } catch (e: FileSystemNotFoundException) { + throw IllegalArgumentException("Only local URLs are supported, got ${url.protocol}") + } catch (e: UnsupportedOperationException) { + throw IllegalArgumentException("Only local URLs are supported, got ${url.protocol}") + } } val implementations = mutableListOf() diff --git a/compiler/tests/org/jetbrains/kotlin/cli/serviceLoaderLite/ServiceLoaderLiteTestWithClassLoader.kt b/compiler/tests/org/jetbrains/kotlin/cli/serviceLoaderLite/ServiceLoaderLiteTestWithClassLoader.kt index 55e952c0770..59fde86ffc8 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/serviceLoaderLite/ServiceLoaderLiteTestWithClassLoader.kt +++ b/compiler/tests/org/jetbrains/kotlin/cli/serviceLoaderLite/ServiceLoaderLiteTestWithClassLoader.kt @@ -31,6 +31,13 @@ class ServiceLoaderLiteTestWithClassLoader : AbstractServiceLoaderLiteTest() { } } + fun testDirWithSpaces() { + classLoaderTest("test dir", impls(NestedComponent::class), clazz()) { classLoader -> + val impls = ServiceLoaderLite.loadImplementations(classLoader) + assertTrue(impls.single() is NestedComponent) + } + } + fun testNestedComponent() { classLoaderTest("test", impls(NestedComponent::class), clazz()) { classLoader -> val impls = ServiceLoaderLite.loadImplementations(classLoader)