aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-10-04 17:32:10 -0700
committerAnton Tananaev <anton@traccar.org>2022-10-04 17:32:10 -0700
commit471de2a758b063cc8d6dd5321cbc459c70b88fd8 (patch)
treee7661e114be1d7137fccff0c39ae5297b92ca7b9 /src
parent503f46939b8d1ac2d7f3955f3f50e314d400f006 (diff)
downloadtrackermap-server-471de2a758b063cc8d6dd5321cbc459c70b88fd8.tar.gz
trackermap-server-471de2a758b063cc8d6dd5321cbc459c70b88fd8.tar.bz2
trackermap-server-471de2a758b063cc8d6dd5321cbc459c70b88fd8.zip
Safer cache request
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/session/cache/CacheManager.java7
1 files changed, 6 insertions, 1 deletions
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)).<T>getValue())
+ .map(id -> {
+ var cacheValue = deviceCache.get(new CacheKey(clazz, id));
+ return cacheValue != null ? cacheValue.<T>getValue() : null;
+ })
+ .filter(Objects::nonNull)
.collect(Collectors.toList());
} finally {
lock.readLock().unlock();