From 3208daf507eea385e15ccf7f9a2d314818f27259 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Fri, 28 Apr 2017 16:01:19 +0100 Subject: [PATCH] Customise the error message according to why Corda cannot boot. (#610) * Customise the error message according to why Corda cannot boot. * Reset system property programmatically for the sake of developers. --- node/src/main/kotlin/net/corda/node/Corda.kt | 15 ++++++++------- .../main/kotlin/net/corda/node/driver/Driver.kt | 3 +-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/node/src/main/kotlin/net/corda/node/Corda.kt b/node/src/main/kotlin/net/corda/node/Corda.kt index aa358da9bc..cedbecdbe2 100644 --- a/node/src/main/kotlin/net/corda/node/Corda.kt +++ b/node/src/main/kotlin/net/corda/node/Corda.kt @@ -169,27 +169,28 @@ private fun assertCanNormalizeEmptyPath() { try { Paths.get("").normalize() } catch (e: ArrayIndexOutOfBoundsException) { - javaIsTooOld() + failStartUp("You are using a version of Java that is not supported (${System.getProperty("java.version")}). Please upgrade to the latest version.") } } -private fun javaIsTooOld(): Nothing { - println(""" -You are using a version of Java that is not supported (${System.getProperty("java.version")}). Please upgrade to the latest version. -Corda will now exit...""") +private fun failStartUp(message: String): Nothing { + println(message) + println("Corda will now exit...") exitProcess(1) } private fun disableJavaDeserialization() { // ObjectInputFilter and friends are in java.io in Java 9 but sun.misc in backports, so we are using the system property interface for portability. - // This property has been set in the Capsule. Anywhere else may be too late. + // This property has already been set in the Capsule. Anywhere else may be too late, but we'll repeat it here for developers. + System.setProperty("jdk.serialFilter", "maxbytes=0") // Attempt at deserialization so that ObjectInputFilter (permanently) inits itself: val data = ByteArrayOutputStream().apply { ObjectOutputStream(this).use { it.writeObject(object : Serializable {}) } }.toByteArray() try { withLevel("java.io.serialization", "WARN") { ObjectInputStream(data.inputStream()).use { it.readObject() } // Logs REJECTED at INFO, which we don't want users to see. } - javaIsTooOld() + // JDK 8u121 is the earliest JDK8 JVM that supports this functionality. + failStartUp("Corda forbids Java deserialisation. Please upgrade to at least JDK 8u121 and set system property 'jdk.serialFilter' to 'maxbytes=0' when booting Corda.") } catch (e: InvalidClassException) { // Good, our system property is honoured. } diff --git a/node/src/main/kotlin/net/corda/node/driver/Driver.kt b/node/src/main/kotlin/net/corda/node/driver/Driver.kt index 89b9d501b8..2e17037672 100644 --- a/node/src/main/kotlin/net/corda/node/driver/Driver.kt +++ b/node/src/main/kotlin/net/corda/node/driver/Driver.kt @@ -575,8 +575,7 @@ class DriverDSL( val systemProperties = overriddenSystemProperties + mapOf( "name" to nodeConf.myLegalName, - "visualvm.display.name" to "corda-${nodeConf.myLegalName}", - "jdk.serialFilter" to "maxbytes=0" // disable deserialisation + "visualvm.display.name" to "corda-${nodeConf.myLegalName}" ) val extraJvmArguments = systemProperties.map { "-D${it.key}=${it.value}" } + "-javaagent:$quasarJarPath"