mirror of
https://github.com/corda/corda.git
synced 2024-12-20 05:28:21 +00:00
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.
This commit is contained in:
parent
f2d138cdab
commit
3208daf507
@ -169,27 +169,28 @@ private fun assertCanNormalizeEmptyPath() {
|
|||||||
try {
|
try {
|
||||||
Paths.get("").normalize()
|
Paths.get("").normalize()
|
||||||
} catch (e: ArrayIndexOutOfBoundsException) {
|
} 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 {
|
private fun failStartUp(message: String): Nothing {
|
||||||
println("""
|
println(message)
|
||||||
You are using a version of Java that is not supported (${System.getProperty("java.version")}). Please upgrade to the latest version.
|
println("Corda will now exit...")
|
||||||
Corda will now exit...""")
|
|
||||||
exitProcess(1)
|
exitProcess(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun disableJavaDeserialization() {
|
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.
|
// 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:
|
// Attempt at deserialization so that ObjectInputFilter (permanently) inits itself:
|
||||||
val data = ByteArrayOutputStream().apply { ObjectOutputStream(this).use { it.writeObject(object : Serializable {}) } }.toByteArray()
|
val data = ByteArrayOutputStream().apply { ObjectOutputStream(this).use { it.writeObject(object : Serializable {}) } }.toByteArray()
|
||||||
try {
|
try {
|
||||||
withLevel("java.io.serialization", "WARN") {
|
withLevel("java.io.serialization", "WARN") {
|
||||||
ObjectInputStream(data.inputStream()).use { it.readObject() } // Logs REJECTED at INFO, which we don't want users to see.
|
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) {
|
} catch (e: InvalidClassException) {
|
||||||
// Good, our system property is honoured.
|
// Good, our system property is honoured.
|
||||||
}
|
}
|
||||||
|
@ -575,8 +575,7 @@ class DriverDSL(
|
|||||||
|
|
||||||
val systemProperties = overriddenSystemProperties + mapOf(
|
val systemProperties = overriddenSystemProperties + mapOf(
|
||||||
"name" to nodeConf.myLegalName,
|
"name" to nodeConf.myLegalName,
|
||||||
"visualvm.display.name" to "corda-${nodeConf.myLegalName}",
|
"visualvm.display.name" to "corda-${nodeConf.myLegalName}"
|
||||||
"jdk.serialFilter" to "maxbytes=0" // disable deserialisation
|
|
||||||
)
|
)
|
||||||
val extraJvmArguments = systemProperties.map { "-D${it.key}=${it.value}" } +
|
val extraJvmArguments = systemProperties.map { "-D${it.key}=${it.value}" } +
|
||||||
"-javaagent:$quasarJarPath"
|
"-javaagent:$quasarJarPath"
|
||||||
|
Loading…
Reference in New Issue
Block a user