From bb7b05be01b19868407d772d37733dff1c9d1fa3 Mon Sep 17 00:00:00 2001 From: skyguard1 Date: Fri, 7 May 2021 17:22:27 +0800 Subject: [PATCH] Add explicit null checks in OpenSslX509KeyManagerFactory (#11230) Motivation: We should add explicit null checks so its easier for people to understand why it throws. Modification: Add explicit checkNotNull(...) Result: Easier to understand for users why it fails. Signed-off-by: xingrufei Co-authored-by: xingrufei --- .../io/netty/handler/ssl/OpenSslX509KeyManagerFactory.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/handler/src/main/java/io/netty/handler/ssl/OpenSslX509KeyManagerFactory.java b/handler/src/main/java/io/netty/handler/ssl/OpenSslX509KeyManagerFactory.java index 88c1c1cb58..df711a0bed 100644 --- a/handler/src/main/java/io/netty/handler/ssl/OpenSslX509KeyManagerFactory.java +++ b/handler/src/main/java/io/netty/handler/ssl/OpenSslX509KeyManagerFactory.java @@ -16,6 +16,7 @@ package io.netty.handler.ssl; import static io.netty.util.internal.ObjectUtil.checkNonEmpty; +import static io.netty.util.internal.ObjectUtil.checkNotNull; import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.UnpooledByteBufAllocator; @@ -254,6 +255,7 @@ public final class OpenSslX509KeyManagerFactory extends KeyManagerFactory { public static OpenSslX509KeyManagerFactory newEngineBased(X509Certificate[] certificateChain, String password) throws CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException { + checkNotNull(certificateChain, "certificateChain"); KeyStore store = new OpenSslKeyStore(certificateChain.clone(), false); store.load(null, null); OpenSslX509KeyManagerFactory factory = new OpenSslX509KeyManagerFactory(); @@ -286,6 +288,7 @@ public final class OpenSslX509KeyManagerFactory extends KeyManagerFactory { public static OpenSslX509KeyManagerFactory newKeyless(X509Certificate... certificateChain) throws CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException { + checkNotNull(certificateChain, "certificateChain"); KeyStore store = new OpenSslKeyStore(certificateChain.clone(), true); store.load(null, null); OpenSslX509KeyManagerFactory factory = new OpenSslX509KeyManagerFactory();