From b8433bada9fce466764dfd76510c024423dd7a7c Mon Sep 17 00:00:00 2001 From: wbzj1110 <13121913082@163.com> Date: Wed, 7 Apr 2021 15:08:02 +0800 Subject: [PATCH] Fix potential null-dereference in CommandHandler #1703 --- .../lettuce/core/protocol/CommandHandler.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/lettuce/core/protocol/CommandHandler.java b/src/main/java/io/lettuce/core/protocol/CommandHandler.java index cf9f12e80c..b6864a57ae 100644 --- a/src/main/java/io/lettuce/core/protocol/CommandHandler.java +++ b/src/main/java/io/lettuce/core/protocol/CommandHandler.java @@ -466,21 +466,26 @@ private void attachTracing(ChannelHandlerContext ctx, RedisCommand comm TracedCommand traced = CommandWrapper.unwrap(command, TracedCommand.class); TraceContextProvider provider = (traced == null ? clientResources.tracing().initialTraceContextProvider() : traced); Tracer tracer = clientResources.tracing().getTracerProvider().getTracer(); - TraceContext context = provider.getTraceContext(); - Tracer.Span span = tracer.nextSpan(context); - span.name(command.getType().name()); + if (provider != null) { - if (tracedEndpoint != null) { - span.remoteEndpoint(tracedEndpoint); - } else { - span.remoteEndpoint(clientResources.tracing().createEndpoint(ctx.channel().remoteAddress())); - } + TraceContext context = provider.getTraceContext(); + + Tracer.Span span = tracer.nextSpan(context); + span.name(command.getType().name()); + + if (tracedEndpoint != null) { + span.remoteEndpoint(tracedEndpoint); + } else { + span.remoteEndpoint(clientResources.tracing().createEndpoint(ctx.channel().remoteAddress())); + } - span.start(command); + span.start(command); - if (traced != null) { - traced.setSpan(span); + if (traced != null) { + traced.setSpan(span); + + } } }