CORDA-1113 - Close classloader (#2637)

* Close classloader after use

(cherry picked from commit 6070bc0)

* Better handling of classloader closing

(cherry picked from commit 2f6413b)
This commit is contained in:
Maksymilian Pawlak 2018-02-28 08:37:42 +00:00 committed by Katelyn Baker
parent 78dbb96089
commit 4285000ff8

View File

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