mirror of https://github.com/apache/nifi.git
NIFI-7279 This closes #4160. Protect against NPE in RedisDistributedMapCacheClientService when value is null
Signed-off-by: Joe Witt <joewitt@apache.org>
This commit is contained in:
parent
5784888082
commit
975f2bdc4f
|
@ -199,7 +199,7 @@ public class RedisDistributedMapCacheClientService extends AbstractControllerSer
|
|||
return withConnection(redisConnection -> {
|
||||
final byte[] k = serialize(key, keySerializer);
|
||||
final byte[] v = redisConnection.get(k);
|
||||
return valueDeserializer.deserialize(v);
|
||||
return v == null ? null : valueDeserializer.deserialize(v);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -168,6 +168,7 @@ public class ITRedisDistributedMapCacheClientService {
|
|||
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
final Serializer<String> stringSerializer = new StringSerializer();
|
||||
final Deserializer<String> stringDeserializer = new StringDeserializer();
|
||||
final Deserializer<String> stringDeserializerWithoutNullCheck = new StringDeserializerWithoutNullCheck();
|
||||
|
||||
final AtomicDistributedMapCacheClient cacheClient = context.getProperty(REDIS_MAP_CACHE).asControllerService(AtomicDistributedMapCacheClient.class);
|
||||
|
||||
|
@ -185,6 +186,10 @@ public class ITRedisDistributedMapCacheClientService {
|
|||
final String retrievedValue = cacheClient.get(key, stringSerializer, stringDeserializer);
|
||||
Assert.assertEquals(value, retrievedValue);
|
||||
|
||||
// verify get returns null for a key that doesn't exist
|
||||
final String missingValue = cacheClient.get("does-not-exist", stringSerializer, stringDeserializerWithoutNullCheck);
|
||||
Assert.assertEquals(null, missingValue);
|
||||
|
||||
// verify remove removes the entry and contains key returns false after
|
||||
Assert.assertTrue(cacheClient.remove(key, stringSerializer));
|
||||
Assert.assertFalse(cacheClient.containsKey(key, stringSerializer));
|
||||
|
@ -261,4 +266,11 @@ public class ITRedisDistributedMapCacheClientService {
|
|||
return input == null ? null : new String(input, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
private static class StringDeserializerWithoutNullCheck implements Deserializer<String> {
|
||||
@Override
|
||||
public String deserialize(byte[] input) throws DeserializationException, IOException {
|
||||
return new String(input, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue