Skip to content

Commit

Permalink
Check getTlsTrustStorePath NPE when user forget to set it. (apach…
Browse files Browse the repository at this point in the history
…e#14253)

If a user sets ``useKeyStoreTls=true`` then forget to set ``getTlsTrustStorePath``, we’re having NPE which becomes hard to debug for users.

- Add NPE check and give use more clear error information.

- [x] Make sure that the change passes the CI checks.

*If `yes` was chosen, please highlight the changes*

  - Dependencies (does it add or upgrade a dependency): (no)
  - The public API: (no)
  - The schema: (no)
  - The default values of configurations: (no)
  - The wire protocol: (no)
  - The rest endpoints: (no)
  - The admin cli options: (no)
  - Anything that affects deployment: (no)

- [x] `no-need-doc`

(cherry picked from commit eca563e)
  • Loading branch information
mattisonchao authored and michaeljmarshall committed Feb 15, 2022
1 parent 26baf84 commit 88805f0
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.pulsar.client.api.AuthenticationDataProvider;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.client.impl.conf.ClientConfigurationData;
import org.apache.pulsar.client.util.ObjectCache;
import org.apache.pulsar.common.protocol.ByteBufPair;
Expand All @@ -38,8 +41,6 @@
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslHandler;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class PulsarChannelInitializer extends ChannelInitializer<SocketChannel> {
Expand All @@ -66,7 +67,10 @@ public PulsarChannelInitializer(ClientConfigurationData conf, Supplier<ClientCnx
if (tlsEnabled) {
if (tlsEnabledWithKeyStore) {
AuthenticationDataProvider authData1 = conf.getAuthentication().getAuthData();

if (StringUtils.isBlank(conf.getTlsTrustStorePath())) {
throw new PulsarClientException("Failed to create TLS context, the tlsTrustStorePath"
+ " need to be configured if useKeyStoreTls enabled");
}
nettySSLContextAutoRefreshBuilder = new NettySSLContextAutoRefreshBuilder(
conf.getSslProvider(),
conf.isTlsAllowInsecureConnection(),
Expand Down

0 comments on commit 88805f0

Please sign in to comment.