Index: trunk/src/org/openstreetmap/josm/data/vector/VectorDataSet.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/vector/VectorDataSet.java	(revision 19693)
+++ trunk/src/org/openstreetmap/josm/data/vector/VectorDataSet.java	(revision 19695)
@@ -253,5 +253,5 @@
     @Override
     public <T extends VectorPrimitive> Collection<T> getPrimitives(Predicate<? super VectorPrimitive> predicate) {
-        Collection<VectorPrimitive> primitives = tryRead(this.readWriteLock, () -> {
+        final Collection<VectorPrimitive> primitives = tryRead(this.readWriteLock, () -> {
             final Storage<MVTTile> dataStore = this.getBestZoomDataStore().orElse(null);
             final Stream<VectorDataStore> dataStoreStream = dataStore != null ? dataStore.stream().map(MVTTile::getData) : Stream.empty();
@@ -364,12 +364,25 @@
         return tryRead(this.readWriteLock, () -> {
             final Storage<MVTTile> dataStore = this.getBestZoomDataStore().orElse(null);
-            Stream<VectorDataStore> dataStoreStream = dataStore != null ? dataStore.stream().map(MVTTile::getData) : Stream.empty();
-                return Stream.concat(dataStoreStream, Stream.of(this.customDataStore)).map(VectorDataStore::getPrimitivesMap)
-                  .flatMap(dataMap -> {
-                    // Synchronize on dataMap to avoid concurrent modification errors
-                    synchronized (dataMap) {
-                        return this.currentSelectedPrimitives.stream().map(dataMap::get).filter(Objects::nonNull);
-                    }
-                }).collect(Collectors.toList());
+            final Stream<VectorDataStore> dataStoreStream = dataStore != null 
+                    ? dataStore.stream().map(MVTTile::getData) 
+                    : Stream.empty();
+
+            return Stream.concat(dataStoreStream, Stream.ofNullable(this.customDataStore))
+                    .map(VectorDataStore::getPrimitivesMap)
+                    .filter(Objects::nonNull)
+                    .flatMap(dataMap -> {
+                        final Map<PrimitiveId, VectorPrimitive> lockObject = dataMap;
+                        synchronized (lockObject) {
+                            final List<VectorPrimitive> selectedInMap = new ArrayList<>();
+                            for (PrimitiveId id : this.currentSelectedPrimitives) {
+                                final VectorPrimitive primitive = lockObject.get(id);
+                                if (primitive != null) {
+                                    selectedInMap.add(primitive);
+                                }
+                            }
+                            return selectedInMap.stream();
+                        }
+                    })
+                    .collect(Collectors.toList());
         }).orElseGet(Collections::emptyList);
     }
@@ -491,5 +504,5 @@
             SelectionChangeEvent<VectorPrimitive, VectorNode, VectorWay, VectorRelation, VectorDataSet>> command) {
         synchronized (this.selectionLock) {
-            SelectionChangeEvent<VectorPrimitive, VectorNode, VectorWay, VectorRelation, VectorDataSet> event =
+            final SelectionChangeEvent<VectorPrimitive, VectorNode, VectorWay, VectorRelation, VectorDataSet> event =
                     command.apply(currentSelectedPrimitives.stream().map(this::getPrimitiveById).collect(Collectors.toSet()));
             if (event.isNop()) {
@@ -636,6 +649,6 @@
      */
     public void setInvisibleLayers(Collection<String> invisibleLayers) {
-        String[] currentInvisibleLayers = invisibleLayers.stream().filter(Objects::nonNull).toArray(String[]::new);
-        List<String> temporaryList = Arrays.asList(currentInvisibleLayers);
+        final String[] currentInvisibleLayers = invisibleLayers.stream().filter(Objects::nonNull).toArray(String[]::new);
+        final List<String> temporaryList = Arrays.asList(currentInvisibleLayers);
         this.dataStoreMap.values().stream().flatMap(Collection::stream).map(MVTTile::getData)
           .forEach(dataStore -> dataStore.getAllPrimitives().parallelStream()
