From b3414267b70d525f1e4cbc83ceea20870d91e761 Mon Sep 17 00:00:00 2001 From: Dominic Fox Date: Mon, 4 Mar 2019 15:32:16 +0000 Subject: [PATCH] Pass in classloader from cordapp loader --- .../corda/core/internal/cordapp/CordappResolver.kt | 5 +++-- .../core/internal/cordapp/CordappResolverTest.kt | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/internal/cordapp/CordappResolver.kt b/core/src/main/kotlin/net/corda/core/internal/cordapp/CordappResolver.kt index 81f95482b7..735b14b009 100644 --- a/core/src/main/kotlin/net/corda/core/internal/cordapp/CordappResolver.kt +++ b/core/src/main/kotlin/net/corda/core/internal/cordapp/CordappResolver.kt @@ -31,7 +31,7 @@ object CordappResolver { * This could happen when trying to run different versions of the same CorDapp on the same node. */ @Synchronized - fun register(cordapp: Cordapp) { + fun register(cordapp: Cordapp, classLoader: ClassLoader) { val existingClasses = cordappClasses.keys val classesToRegister = cordapp.cordappClasses.toSet() val notAlreadyRegisteredClasses = classesToRegister - existingClasses @@ -41,7 +41,7 @@ object CordappResolver { for ((className, registeredCordapps) in alreadyRegistered) { if (registeredCordapps.any { it.jarHash == cordapp.jarHash }) continue - if (duplicateRegistrationFilter.shouldNotify(className, cordapp::class.java.classLoader)) { + if (duplicateRegistrationFilter.shouldNotify(className, classLoader)) { logger.warn("More than one CorDapp registered for $className.") } cordappClasses[className] = registeredCordapps + cordapp @@ -97,6 +97,7 @@ internal class DuplicateRegistrationFilter(private val ignoreList: Set) alreadySeen += className if (className.canBeIgnored) return false + println("Checking status of $className with $classLoader") return className.isContractClass(classLoader) } diff --git a/core/src/test/kotlin/net/corda/core/internal/cordapp/CordappResolverTest.kt b/core/src/test/kotlin/net/corda/core/internal/cordapp/CordappResolverTest.kt index a491e254de..516c3818b2 100644 --- a/core/src/test/kotlin/net/corda/core/internal/cordapp/CordappResolverTest.kt +++ b/core/src/test/kotlin/net/corda/core/internal/cordapp/CordappResolverTest.kt @@ -14,6 +14,8 @@ class CordappResolverTest { CordappResolver.clear() } + private val classLoader = ClassLoader.getSystemClassLoader() + @Test fun `the correct cordapp resolver is used after calling withCordappInfo`() { val defaultTargetVersion = 222 @@ -22,7 +24,7 @@ class CordappResolverTest { contractClassNames = listOf(javaClass.name), minimumPlatformVersion = 3, targetPlatformVersion = defaultTargetVersion - )) + ), classLoader) assertEquals(defaultTargetVersion, CordappResolver.currentTargetVersion) val expectedTargetVersion = 555 @@ -39,12 +41,12 @@ class CordappResolverTest { contractClassNames = listOf(javaClass.name), minimumPlatformVersion = 3, targetPlatformVersion = 222 - )) + ), classLoader) CordappResolver.register(CordappImpl.TEST_INSTANCE.copy( contractClassNames = listOf(javaClass.name), minimumPlatformVersion = 2, targetPlatformVersion = 456 - )) + ), classLoader) assertThat(CordappResolver.currentCordapp).isNotNull() } @@ -55,13 +57,13 @@ class CordappResolverTest { minimumPlatformVersion = 3, targetPlatformVersion = 222, jarHash = SecureHash.randomSHA256() - )) + ), classLoader) CordappResolver.register(CordappImpl.TEST_INSTANCE.copy( contractClassNames = listOf(javaClass.name), minimumPlatformVersion = 2, targetPlatformVersion = 456, jarHash = SecureHash.randomSHA256() - )) + ), classLoader) assertThat(CordappResolver.currentCordapp).isNull() } }