lettuce
lettuce copied to clipboard
Lettuce doesn't handle null response for Redis key (NullPointerException)
Bug Report
The problem is similar to /issues/1474 which was related to a different place in the code but has the same symptoms.
When I try to get a value from
Current Behavior
Lettuce throws a NullPointerException
when I try to get a value range for a zset
by a key that is absent or has a null value.
At the same moment, the 'size' request works as expected for the same keys.
Stack trace
Caused by: java.lang.NullPointerException: Cannot invoke "java.nio.ByteBuffer.remaining()" because "buffer" is null
at io.lettuce.core.codec.ByteArrayCodec.getBytes(ByteArrayCodec.java:84)
at io.lettuce.core.codec.ByteArrayCodec.decodeValue(ByteArrayCodec.java:64)
at io.lettuce.core.codec.ByteArrayCodec.decodeValue(ByteArrayCodec.java:28)
at io.lettuce.core.output.ScoredValueListOutput.set(ScoredValueListOutput.java:54)
at io.lettuce.core.protocol.RedisStateMachine.safeSet(RedisStateMachine.java:806)
at io.lettuce.core.protocol.RedisStateMachine.handleNull(RedisStateMachine.java:397)
at io.lettuce.core.protocol.RedisStateMachine$State$Type.handle(RedisStateMachine.java:205)
at io.lettuce.core.protocol.RedisStateMachine.doDecode(RedisStateMachine.java:339)
at io.lettuce.core.protocol.RedisStateMachine.decode(RedisStateMachine.java:300)
at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:840)
at io.lettuce.core.protocol.CommandHandler.decode0(CommandHandler.java:791)
at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:765)
at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:657)
at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:597)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Input Code
Input Code
stringRedisTemplate.opsForZSet().rangeWithScores("KEY_WITH_NULL_VALUE_OR_ABSENT", 0, 0)
Expected behavior/code
no NPE
Environment
- Lettuce version(s): 6.3.1.RELEASE
- Redis version: 5.1.1