Check java version is above 1.8.0_171 on node startup (#3870)

This commit is contained in:
Dan Newton 2018-09-19 23:34:03 +08:00 committed by Shams Asari
parent ae4dfc93da
commit 6775ffa2e6
2 changed files with 11 additions and 12 deletions

View File

@ -77,6 +77,7 @@ buildscript {
// Update 121 is required for ObjectInputFilter.
// Updates [131, 161] also have zip compression bugs on MacOS (High Sierra).
// when the java version in NodeStartup.hasMinimumJavaVersion() changes, so must this check
ext.java8_minUpdateVersion = '171'
repositories {

View File

@ -33,6 +33,7 @@ import net.corda.nodeapi.internal.config.UnknownConfigurationKeysException
import net.corda.nodeapi.internal.persistence.CouldNotCreateDataSourceException
import net.corda.nodeapi.internal.persistence.DatabaseIncompatibleException
import net.corda.tools.shell.InteractiveShell
import org.apache.commons.lang.SystemUtils
import org.fusesource.jansi.Ansi
import org.slf4j.bridge.SLF4JBridgeHandler
import picocli.CommandLine.Mixin
@ -130,14 +131,21 @@ open class NodeStartup : CordaCliWrapper("corda", "Runs a Corda Node") {
}
private fun isValidJavaVersion(): Boolean {
if (!canNormalizeEmptyPath()) {
println("You are using a version of Java that is not supported (${System.getProperty("java.version")}). Please upgrade to the latest supported version.")
if (!hasMinimumJavaVersion()) {
println("You are using a version of Java that is not supported (${SystemUtils.JAVA_VERSION}). Please upgrade to the latest version of Java 8.")
println("Corda will now exit...")
return false
}
return true
}
private fun hasMinimumJavaVersion(): Boolean {
// when the ext.java8_minUpdateVersion gradle constant changes, so must this check
val major = SystemUtils.JAVA_VERSION_FLOAT
val update = SystemUtils.JAVA_VERSION.substringAfter("_").toLong()
return major == 1.8F && update >= 171
}
// TODO: Reconsider if automatic re-registration should be applied when something failed during initial registration.
// There might be cases where the node user should investigate what went wrong before registering again.
private fun checkUnfinishedRegistration() {
@ -506,16 +514,6 @@ open class NodeStartup : CordaCliWrapper("corda", "Runs a Corda Node") {
return hostName
}
private fun canNormalizeEmptyPath(): Boolean {
// Check we're not running a version of Java with a known bug: https://github.com/corda/corda/issues/83
return try {
Paths.get("").normalize()
true
} catch (e: ArrayIndexOutOfBoundsException) {
false
}
}
open fun drawBanner(versionInfo: VersionInfo) {
Emoji.renderIfSupported {
val messages = arrayListOf(