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 <xingrufei@sogou-inc.com>

Co-authored-by: xingrufei <xingrufei@sogou-inc.com>
This commit is contained in:
skyguard1 2021-05-07 17:22:27 +08:00 committed by Norman Maurer
parent fe5a56fc01
commit e10c1af314

View File

@ -17,6 +17,7 @@ package io.netty.handler.ssl;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import static io.netty.util.internal.ObjectUtil.checkNonEmpty; 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.ByteBufAllocator;
import io.netty.buffer.UnpooledByteBufAllocator; import io.netty.buffer.UnpooledByteBufAllocator;
@ -254,6 +255,7 @@ public final class OpenSslX509KeyManagerFactory extends KeyManagerFactory {
public static OpenSslX509KeyManagerFactory newEngineBased(X509Certificate[] certificateChain, String password) public static OpenSslX509KeyManagerFactory newEngineBased(X509Certificate[] certificateChain, String password)
throws CertificateException, IOException, throws CertificateException, IOException,
KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException { KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
checkNotNull(certificateChain, "certificateChain");
KeyStore store = new OpenSslKeyStore(certificateChain.clone(), false); KeyStore store = new OpenSslKeyStore(certificateChain.clone(), false);
store.load(null, null); store.load(null, null);
OpenSslX509KeyManagerFactory factory = new OpenSslX509KeyManagerFactory(); OpenSslX509KeyManagerFactory factory = new OpenSslX509KeyManagerFactory();
@ -286,6 +288,7 @@ public final class OpenSslX509KeyManagerFactory extends KeyManagerFactory {
public static OpenSslX509KeyManagerFactory newKeyless(X509Certificate... certificateChain) public static OpenSslX509KeyManagerFactory newKeyless(X509Certificate... certificateChain)
throws CertificateException, IOException, throws CertificateException, IOException,
KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException { KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
checkNotNull(certificateChain, "certificateChain");
KeyStore store = new OpenSslKeyStore(certificateChain.clone(), true); KeyStore store = new OpenSslKeyStore(certificateChain.clone(), true);
store.load(null, null); store.load(null, null);
OpenSslX509KeyManagerFactory factory = new OpenSslX509KeyManagerFactory(); OpenSslX509KeyManagerFactory factory = new OpenSslX509KeyManagerFactory();