Index: trunk/src/org/openstreetmap/josm/gui/history/HistoryLoadTask.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/history/HistoryLoadTask.java	(revision 16204)
+++ trunk/src/org/openstreetmap/josm/gui/history/HistoryLoadTask.java	(revision 16205)
@@ -7,7 +7,8 @@
 import java.awt.Component;
 import java.io.IOException;
+import java.net.HttpURLConnection;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Objects;
@@ -24,4 +25,5 @@
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 import org.openstreetmap.josm.io.ChangesetQuery;
+import org.openstreetmap.josm.io.OsmApiException;
 import org.openstreetmap.josm.io.OsmServerChangesetReader;
 import org.openstreetmap.josm.io.OsmServerHistoryReader;
@@ -51,8 +53,10 @@
     private boolean canceled;
     private Exception lastException;
-    private final Set<PrimitiveId> toLoad = new HashSet<>();
+    private final Set<PrimitiveId> toLoad = new LinkedHashSet<>();
     private HistoryDataSet loadedData;
     private OsmServerHistoryReader reader;
     private boolean getChangesetData = true;
+    private boolean collectMissing;
+    private final Set<PrimitiveId> missingPrimitives = new LinkedHashSet<>();
 
     /**
@@ -194,5 +198,5 @@
         progressMonitor.indeterminateSubTask(tr(msg, Long.toString(pid.getUniqueId())));
         reader = null;
-        HistoryDataSet ds;
+        HistoryDataSet ds = null;
         try {
             reader = new OsmServerHistoryReader(pid.getType(), pid.getUniqueId());
@@ -202,4 +206,12 @@
                 ds = reader.parseHistory(progressMonitor.createSubTaskMonitor(1, false));
             }
+        } catch (OsmApiException e) {
+            if (canceled)
+                return;
+            if (e.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND && collectMissing) {
+                missingPrimitives.add(pid);
+            } else {
+                throw e;
+            }
         } catch (OsmTransferException e) {
             if (canceled)
@@ -207,5 +219,7 @@
             throw e;
         }
-        loadedData.mergeInto(ds);
+        if (ds != null) {
+            loadedData.mergeInto(ds);
+        }
     }
 
@@ -267,3 +281,26 @@
         getChangesetData = b;
     }
+
+    /**
+     * Determine if missing primitives should be collected. By default they are not collected
+     * and the first missing object terminates the task.
+     * @param b true means collect missing data and continue.
+     * @since 16205
+     */
+    public void setCollectMissing(boolean b) {
+        collectMissing = b;
+    }
+
+    /**
+     * replies the set of ids of all primitives for which a fetch request to the
+     * server was submitted but which are not available from the server (the server
+     * replied a return code of 404)
+     * @since 16205
+     *
+     * @return the set of ids of missing primitives
+     */
+    public Set<PrimitiveId> getMissingPrimitives() {
+        return missingPrimitives;
+    }
+
 }
