[minor] Fix URL conversion to the file

possibly fixes the exception from https://stackoverflow.com/questions/57727150/kotlin-script-engine-with-spring-boot-self-running-war
This commit is contained in:
Ilya Chernikov
2019-10-01 15:13:39 +02:00
parent 3fec15202f
commit cb5622fc8b
2 changed files with 7 additions and 3 deletions
@@ -94,10 +94,14 @@ fun tryGetResourcePathForClassByName(name: String, classLoader: ClassLoader): Fi
internal fun URL.toFileOrNull() =
try {
File(toURI().schemeSpecificPart).canonicalFile
File(toURI())
} catch (e: IllegalArgumentException) {
null
} catch (e: java.net.URISyntaxException) {
null
} ?: run {
if (protocol != "file") null
else File(file).canonicalFile
else File(file)
}
internal fun URL.toContainingJarOrNull(): File? =