From a9d9b668bc3f8ab03c0a57da75bc58ab4ead84d4 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 23 Sep 2019 18:26:21 +0100 Subject: [PATCH] CORDA-2050: Do not add java.lang.Class fields and properties to local type cache. (#5511) * Fix SLF4J logging for example Gradle project. * Stop adding java.lang.Class's internal fields and properties to the local type cache. This allows us to fix ArraySerializer for the DJVM. --- docs/source/example-code/build.gradle | 21 ++++++++++--------- .../internal/amqp/ArraySerializer.kt | 4 +++- .../model/LocalTypeInformationBuilder.kt | 7 ++++++- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/source/example-code/build.gradle b/docs/source/example-code/build.gradle index 3de906ce19..92e63567ba 100644 --- a/docs/source/example-code/build.gradle +++ b/docs/source/example-code/build.gradle @@ -6,6 +6,12 @@ apply plugin: 'net.corda.plugins.quasar-utils' configurations { integrationTestCompile.extendsFrom testCompile integrationTestRuntime.extendsFrom testRuntime + + compile { + // We already have a SLF4J implementation on our runtime classpath, + // and we don't need another one. + exclude group: "org.apache.logging.log4j" + } } sourceSets { @@ -33,14 +39,9 @@ dependencies { compile project(':core') compile project(':client:jfx') - compile (project(':node-driver')) { - // We already have a SLF4J implementation on our runtime classpath, - // and we don't need another one. - exclude group: 'org.apache.logging.log4j' - } - compile (project(':webserver')) { - exclude group: "org.apache.logging.log4j" - } + compile project(':node-driver') + compile project(':webserver') + testCompile project(':test-utils') compile "org.graphstream:gs-core:1.3" @@ -49,8 +50,8 @@ dependencies { exclude group: "junit" } - compile project(path: ":node:capsule", configuration: 'runtimeArtifacts') - compile project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts') + cordaRuntime project(path: ":node:capsule", configuration: 'runtimeArtifacts') + cordaRuntime project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts') // CorDapps: dependent flows and services compile project(':finance:contracts') diff --git a/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/ArraySerializer.kt b/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/ArraySerializer.kt index 3e2266f63a..63b6ce73b7 100644 --- a/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/ArraySerializer.kt +++ b/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/ArraySerializer.kt @@ -88,7 +88,9 @@ open class ArraySerializer(override val type: Type, factory: LocalSerializerFact context: SerializationContext ): Any { if (obj is List<*>) { - return obj.map { input.readObjectOrNull(it, schemas, elementType, context) }.toArrayOfType(elementType) + return obj.map { + input.readObjectOrNull(redescribe(it, elementType), schemas, elementType, context) + }.toArrayOfType(elementType) } else throw AMQPNotSerializableException(type, "Expected a List but found $obj") } diff --git a/serialization/src/main/kotlin/net/corda/serialization/internal/model/LocalTypeInformationBuilder.kt b/serialization/src/main/kotlin/net/corda/serialization/internal/model/LocalTypeInformationBuilder.kt index f6741c41c3..7526b3c8f2 100644 --- a/serialization/src/main/kotlin/net/corda/serialization/internal/model/LocalTypeInformationBuilder.kt +++ b/serialization/src/main/kotlin/net/corda/serialization/internal/model/LocalTypeInformationBuilder.kt @@ -209,7 +209,12 @@ internal data class LocalTypeInformationBuilder(val lookup: LocalTypeLookup, observedType = type, typeIdentifier = typeIdentifier, constructor = null, - properties = buildReadOnlyProperties(rawType), + properties = if (rawType == Class::class.java) { + // Do NOT drill down into the internals of java.lang.Class. + emptyMap() + } else { + buildReadOnlyProperties(rawType) + }, superclass = superclassInformation, interfaces = interfaceInformation, typeParameters = typeParameterInformation,