From 6ad59d14d70e2c55a328d0b011ef3dd91299e4c6 Mon Sep 17 00:00:00 2001 From: Johno Crawford Date: Mon, 28 Oct 2019 14:47:00 +0100 Subject: [PATCH] Complete todo in SelfSignedCertificate (#9720) Motivation: Easier to debug SelfSignedCertificate failures. Modifications: Add first throwable as suppressed to thrown exception. Result: Less technical debt. --- .../io/netty/handler/ssl/util/SelfSignedCertificate.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/handler/src/main/java/io/netty/handler/ssl/util/SelfSignedCertificate.java b/handler/src/main/java/io/netty/handler/ssl/util/SelfSignedCertificate.java index 3bf4285a64..c0b8467bd7 100644 --- a/handler/src/main/java/io/netty/handler/ssl/util/SelfSignedCertificate.java +++ b/handler/src/main/java/io/netty/handler/ssl/util/SelfSignedCertificate.java @@ -21,6 +21,7 @@ import io.netty.buffer.Unpooled; import io.netty.handler.codec.base64.Base64; import io.netty.util.CharsetUtil; import io.netty.util.internal.SystemPropertyUtil; +import io.netty.util.internal.ThrowableUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -162,10 +163,11 @@ public final class SelfSignedCertificate { paths = BouncyCastleSelfSignedCertGenerator.generate(fqdn, keypair, random, notBefore, notAfter); } catch (Throwable t2) { logger.debug("Failed to generate a self-signed X.509 certificate using Bouncy Castle:", t2); - throw new CertificateException( + final CertificateException certificateException = new CertificateException( "No provider succeeded to generate a self-signed certificate. " + "See debug log for the root cause.", t2); - // TODO: consider using Java 7 addSuppressed to append t + ThrowableUtil.addSuppressed(certificateException, t); + throw certificateException; } }