From 369b1e92f9c22ce9b57e88f6b0fab750fcbab121 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Wed, 20 Aug 2025 14:52:54 +0200 Subject: [PATCH] Improve null-safety of module/spring-boot-kafka See gh-46926 --- .../SslBundleSslEngineFactory.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/module/spring-boot-kafka/src/main/java/org/springframework/boot/kafka/autoconfigure/SslBundleSslEngineFactory.java b/module/spring-boot-kafka/src/main/java/org/springframework/boot/kafka/autoconfigure/SslBundleSslEngineFactory.java index 41241fbabbd..d77e7afa670 100644 --- a/module/spring-boot-kafka/src/main/java/org/springframework/boot/kafka/autoconfigure/SslBundleSslEngineFactory.java +++ b/module/spring-boot-kafka/src/main/java/org/springframework/boot/kafka/autoconfigure/SslBundleSslEngineFactory.java @@ -59,8 +59,9 @@ public class SslBundleSslEngineFactory implements SslEngineFactory { @Override public SSLEngine createClientSslEngine(String peerHost, int peerPort, String endpointIdentification) { - Assert.state(this.sslBundle != null, "'sslBundle' must not be null"); - SSLEngine sslEngine = this.sslBundle.createSslContext().createSSLEngine(peerHost, peerPort); + SslBundle sslBundle = this.sslBundle; + Assert.state(sslBundle != null, "'sslBundle' must not be null"); + SSLEngine sslEngine = sslBundle.createSslContext().createSSLEngine(peerHost, peerPort); sslEngine.setUseClientMode(true); SSLParameters sslParams = sslEngine.getSSLParameters(); sslParams.setEndpointIdentificationAlgorithm(endpointIdentification); @@ -70,8 +71,9 @@ public class SslBundleSslEngineFactory implements SslEngineFactory { @Override public SSLEngine createServerSslEngine(String peerHost, int peerPort) { - Assert.state(this.sslBundle != null, "'sslBundle' must not be null"); - SSLEngine sslEngine = this.sslBundle.createSslContext().createSSLEngine(peerHost, peerPort); + SslBundle sslBundle = this.sslBundle; + Assert.state(sslBundle != null, "'sslBundle' must not be null"); + SSLEngine sslEngine = sslBundle.createSslContext().createSSLEngine(peerHost, peerPort); sslEngine.setUseClientMode(false); return sslEngine; } @@ -88,14 +90,16 @@ public class SslBundleSslEngineFactory implements SslEngineFactory { @Override public @Nullable KeyStore keystore() { - Assert.state(this.sslBundle != null, "'sslBundle' must not be null"); - return this.sslBundle.getStores().getKeyStore(); + SslBundle sslBundle = this.sslBundle; + Assert.state(sslBundle != null, "'sslBundle' must not be null"); + return sslBundle.getStores().getKeyStore(); } @Override public @Nullable KeyStore truststore() { - Assert.state(this.sslBundle != null, "'sslBundle' must not be null"); - return this.sslBundle.getStores().getTrustStore(); + SslBundle sslBundle = this.sslBundle; + Assert.state(sslBundle != null, "'sslBundle' must not be null"); + return sslBundle.getStores().getTrustStore(); } }