Improved classloader closing (#2650)

* Better handling of classloader closing
This commit is contained in:
Maksymilian Pawlak 2018-02-27 11:15:23 +00:00 committed by GitHub
parent 3391810101
commit 3066926f0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,10 +24,9 @@ fun scanJarForContracts(cordappJarPath: String): List<ContractClassName> {
val contracts = (scanResult.getNamesOfClassesImplementing(Contract::class.qualifiedName) ).distinct()
// Only keep instantiable contracts
val classLoader = URLClassLoader(arrayOf(File(cordappJarPath).toURL()), currentClassLoader)
val concreteContracts = contracts.map(classLoader::loadClass).filter { !it.isInterface && !Modifier.isAbstract(it.modifiers) }
classLoader.close()
return concreteContracts.map { it.name }
return URLClassLoader(arrayOf(File(cordappJarPath).toURL()), currentClassLoader).use {
contracts.map(it::loadClass).filter { !it.isInterface && !Modifier.isAbstract(it.modifiers) }
}.map { it.name }
}
fun <T> withContractsInJar(jarInputStream: InputStream, withContracts: (List<ContractClassName>, InputStream) -> T): T {