From 471de2a758b063cc8d6dd5321cbc459c70b88fd8 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 4 Oct 2022 17:32:10 -0700 Subject: Safer cache request --- src/main/java/org/traccar/session/cache/CacheManager.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java index 64397b368..ed67ed70e 100644 --- a/src/main/java/org/traccar/session/cache/CacheManager.java +++ b/src/main/java/org/traccar/session/cache/CacheManager.java @@ -48,6 +48,7 @@ import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -102,7 +103,11 @@ public class CacheManager implements BroadcastInterface { try { lock.readLock().lock(); return deviceLinks.get(deviceId).get(clazz).stream() - .map(id -> deviceCache.get(new CacheKey(clazz, id)).getValue()) + .map(id -> { + var cacheValue = deviceCache.get(new CacheKey(clazz, id)); + return cacheValue != null ? cacheValue.getValue() : null; + }) + .filter(Objects::nonNull) .collect(Collectors.toList()); } finally { lock.readLock().unlock(); -- cgit v1.2.3