From c1542f386aff2c5b2d97a0df9b272d8b1cfc6717 Mon Sep 17 00:00:00 2001 From: Andrius Dagys Date: Thu, 27 Jun 2019 15:33:38 +0300 Subject: [PATCH] CORDA-2996: NotaryLoader - improve exception handling (#5210) Ignore InvocationTargetException and only propagate the cause to avoid noise. --- .../kotlin/net/corda/node/utilities/NotaryLoader.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/node/src/main/kotlin/net/corda/node/utilities/NotaryLoader.kt b/node/src/main/kotlin/net/corda/node/utilities/NotaryLoader.kt index e1bd2e2a2a..12686caf39 100644 --- a/node/src/main/kotlin/net/corda/node/utilities/NotaryLoader.kt +++ b/node/src/main/kotlin/net/corda/node/utilities/NotaryLoader.kt @@ -13,6 +13,7 @@ import net.corda.node.services.config.NotaryConfig import net.corda.node.services.transactions.SimpleNotaryService import net.corda.notary.experimental.bftsmart.BFTSmartNotaryService import net.corda.notary.experimental.raft.RaftNotaryService +import java.lang.reflect.InvocationTargetException import java.security.PublicKey class NotaryLoader( @@ -61,7 +62,7 @@ class NotaryLoader( log.info("Starting notary service: $serviceClass") val notaryKey = myNotaryIdentity?.owningKey - ?: throw IllegalArgumentException("Unable to start notary service $serviceClass: notary identity not found") + ?: throw IllegalArgumentException("Unable to start notary service: notary identity not found") /** Some notary implementations only work with Java serialization. */ maybeInstallSerializationFilter(serviceClass) @@ -69,7 +70,12 @@ class NotaryLoader( val constructor = serviceClass .getDeclaredConstructor(ServiceHubInternal::class.java, PublicKey::class.java) .apply { isAccessible = true } - return constructor.newInstance(services, notaryKey) + try { + return constructor.newInstance(services, notaryKey) + } catch (e: InvocationTargetException) { + log.error("Exception occurred when starting notary service") + throw e.cause ?: e + } } /** Validates that the notary is correctly configured by comparing the configured type against the type advertised in the network map cache */