Index: core/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
===================================================================
--- core/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java	(revision 5476)
+++ core/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java	(working copy)
@@ -15,15 +15,21 @@
 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
 import org.openstreetmap.josm.gui.layer.GpxLayer;
 import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 import org.openstreetmap.josm.gui.progress.ProgressTaskId;
 import org.openstreetmap.josm.gui.progress.ProgressTaskIds;
 import org.openstreetmap.josm.io.BoundingBoxDownloader;
+import org.openstreetmap.josm.io.GpxImporter;
+import org.openstreetmap.josm.io.GpxImporter.GpxImporterData;
 import org.openstreetmap.josm.io.OsmServerLocationReader;
 import org.openstreetmap.josm.io.OsmServerReader;
 import org.openstreetmap.josm.io.OsmTransferException;
 import org.xml.sax.SAXException;
 
+/**
+ * Task allowing to download GPS data.
+ */
 public class DownloadGpsTask extends AbstractDownloadTask {
 
     private DownloadTask downloadTask;
@@ -114,25 +120,46 @@
             if (rawData == null)
                 return;
             String name = newLayerName != null ? newLayerName : tr("Downloaded GPX Data");
-            GpxLayer layer = new GpxLayer(rawData, name);
-            Layer x = findMergeLayer();
-            if (newLayer || x == null) {
+            
+            GpxImporterData layers = GpxImporter.loadLayers(rawData, reader.isGpxParsedProperly(), name, tr("Markers from {0}", name));
+            
+            GpxLayer gpxLayer = addOrMergeLayer(layers.gpxLayer, findGpxMergeLayer());
+            addOrMergeLayer(layers.markerLayer, findMarkerMergeLayer(gpxLayer));
+            
+            layers.postLayerTask.run();
+        }
+        
+        private <L extends Layer> L addOrMergeLayer(L layer, L mergeLayer) {
+            if (layer == null) return null;
+            if (newLayer || mergeLayer == null) {
                 Main.main.addLayer(layer);
+                return layer;
             } else {
-                x.mergeFrom(layer);
+                mergeLayer.mergeFrom(layer);
                 Main.map.repaint();
+                return mergeLayer;
             }
         }
 
-        private Layer findMergeLayer() {
-            boolean merge = Main.pref.getBoolean("download.gps.mergeWithLocal", false);
+        private GpxLayer findGpxMergeLayer() {
             if (!Main.isDisplayingMapView())
                 return null;
+            boolean merge = Main.pref.getBoolean("download.gps.mergeWithLocal", false);
             Layer active = Main.map.mapView.getActiveLayer();
             if (active != null && active instanceof GpxLayer && (merge || ((GpxLayer)active).data.fromServer))
-                return active;
-            for (Layer l : Main.map.mapView.getAllLayers()) {
-                if (l instanceof GpxLayer &&  (merge || ((GpxLayer)l).data.fromServer))
+                return (GpxLayer) active;
+            for (GpxLayer l : Main.map.mapView.getLayersOfType(GpxLayer.class)) {
+                if (merge || l.data.fromServer)
+                    return l;
+            }
+            return null;
+        }
+        
+        private MarkerLayer findMarkerMergeLayer(GpxLayer fromLayer) {
+            if (!Main.isDisplayingMapView())
+                return null;
+            for (MarkerLayer l : Main.map.mapView.getLayersOfType(MarkerLayer.class)) {
+                if (fromLayer != null && l.fromLayer == fromLayer)
                     return l;
             }
             return null;
Index: core/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
===================================================================
--- core/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java	(revision 5476)
+++ core/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java	(working copy)
@@ -42,7 +42,7 @@
             }
             progressMonitor.setTicks(0);
             GpxReader reader = new GpxReader(in);
-            reader.parse(false);
+            gpxParsedProperly = reader.parse(false);
             GpxData currentGpx = reader.data;
             if (result == null) {
                 result = currentGpx;
Index: core/src/org/openstreetmap/josm/io/GpxImporter.java
===================================================================
--- core/src/org/openstreetmap/josm/io/GpxImporter.java	(revision 5476)
+++ core/src/org/openstreetmap/josm/io/GpxImporter.java	(working copy)
@@ -13,28 +13,52 @@
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.ExtensionFileFilter;
+import org.openstreetmap.josm.data.gpx.GpxData;
 import org.openstreetmap.josm.gui.layer.GpxLayer;
 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 import org.openstreetmap.josm.gui.util.GuiHelper;
 import org.xml.sax.SAXException;
 
+/**
+ * File importer allowing to import GPX files (*.gpx/gpx.gz files).
+ *
+ */
 public class GpxImporter extends FileImporter {
 
+    /**
+     * The GPX file filter (*.gpx and *.gpx.gz files).
+     */
     public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
             "gpx,gpx.gz", "gpx", tr("GPX Files") + " (*.gpx *.gpx.gz)");
     
-    protected static class GpxImporterData {
+    /**
+     * Utility class containing imported GPX and marker layers, and a task to run after they are added to MapView. 
+     */
+    public static class GpxImporterData {
+        /**
+         * The imported GPX layer. May be null if no GPX data.
+         */
         public GpxLayer gpxLayer;
+        /**
+         * The imported marker layer. May be null if no marker.
+         */
         public MarkerLayer markerLayer;
+        /**
+         * The task to run after GPX and/or marker layer has been added to MapView.
+         */
         public Runnable postLayerTask;
     }
 
+    /**
+     * Constructs a new {@code GpxImporter}.
+     */
     public GpxImporter() {
         super(FILE_FILTER);
     }
 
-    @Override public void importData(File file, ProgressMonitor progressMonitor) throws IOException {
+    @Override
+    public void importData(File file, ProgressMonitor progressMonitor) throws IOException {
         InputStream is;
         if (file.getName().endsWith(".gpx.gz")) {
             is = new GZIPInputStream(new FileInputStream(file));
@@ -42,8 +66,24 @@
             is = new FileInputStream(file);
         }
         String fileName = file.getName();
-        final GpxImporterData data = loadLayers(is, file, fileName, tr("Markers from {0}", fileName), progressMonitor);
-
+        
+        try {
+            GpxReader r = new GpxReader(is);
+            boolean parsedProperly = r.parse(true);
+            r.data.storageFile = file;
+            addLayers(loadLayers(r.data, parsedProperly, fileName, tr("Markers from {0}", fileName)));
+        } catch (SAXException e) {
+            e.printStackTrace();
+            throw new IOException(tr("Parsing data for layer ''{0}'' failed", fileName));
+        }
+    }
+    
+    /**
+     * Adds the specified GPX and marker layers to Map.main
+     * @param data The layers to add
+     * @see #loadLayers
+     */
+    public static void addLayers(final GpxImporterData data) {
         // FIXME: remove UI stuff from the IO subsystem
         GuiHelper.runInEDT(new Runnable() {
             public void run() {
@@ -58,45 +98,45 @@
         });
     }
 
-    public GpxImporterData loadLayers(InputStream is, final File associatedFile,
-            final String gpxLayerName, String markerLayerName, ProgressMonitor progressMonitor) throws IOException {
-        final GpxImporterData data = new GpxImporterData();
-        try {
-            final GpxReader r = new GpxReader(is);
-            final boolean parsedProperly = r.parse(true);
-            r.data.storageFile = associatedFile;
-            if (r.data.hasRoutePoints() || r.data.hasTrackPoints()) {
-                data.gpxLayer = new GpxLayer(r.data, gpxLayerName, associatedFile != null);
+    /**
+     * Replies the new GPX and marker layers corresponding to the specified GPX data.
+     * @param data The GPX data
+     * @param parsedProperly True if GPX data has been properly parsed by {@link GpxReader#parse}
+     * @param gpxLayerName The GPX layer name
+     * @param markerLayerName The marker layer name
+     * @return the new GPX and marker layers corresponding to the specified GPX data, to be used with {@link #addLayers}
+     * @see #addLayers
+     */
+    public static GpxImporterData loadLayers(final GpxData data, final boolean parsedProperly, final String gpxLayerName, String markerLayerName) {
+        final GpxImporterData result = new GpxImporterData();
+        if (data.hasRoutePoints() || data.hasTrackPoints()) {
+            result.gpxLayer = new GpxLayer(data, gpxLayerName, data.storageFile != null);
+        }
+        if (Main.pref.getBoolean("marker.makeautomarkers", true) && !data.waypoints.isEmpty()) {
+            result.markerLayer = new MarkerLayer(data, markerLayerName, data.storageFile, result.gpxLayer, false);
+            if (result.markerLayer.data.size() == 0) {
+                result.markerLayer = null;
             }
-            if (Main.pref.getBoolean("marker.makeautomarkers", true) && !r.data.waypoints.isEmpty()) {
-                data.markerLayer = new MarkerLayer(r.data, markerLayerName, associatedFile, data.gpxLayer, false);
-                if (data.markerLayer.data.size() == 0) {
-                    data.markerLayer = null;
+        }
+        result.postLayerTask = new Runnable() {
+            @Override
+            public void run() {
+                if (result.markerLayer != null) {
+                    result.markerLayer.addMouseHandler();
                 }
-            }
-            data.postLayerTask = new Runnable() {
-                @Override
-                public void run() {
-                    if (data.markerLayer != null) {
-                        data.markerLayer.addMouseHandler();
-                    }
-                    if (!parsedProperly) {
-                        String msg;
-                        if (associatedFile == null) {
-                            msg = tr("Error occurred while parsing gpx data for layer ''{0}''. Only a part of the file will be available.",
-                                    gpxLayerName);
-                        } else {
-                            msg = tr("Error occurred while parsing gpx file ''{0}''. Only a part of the file will be available.",
-                                    associatedFile.getPath());
-                        }
-                        JOptionPane.showMessageDialog(null, msg);
+                if (!parsedProperly) {
+                    String msg;
+                    if (data.storageFile == null) {
+                        msg = tr("Error occurred while parsing gpx data for layer ''{0}''. Only a part of the file will be available.",
+                                gpxLayerName);
+                    } else {
+                        msg = tr("Error occurred while parsing gpx file ''{0}''. Only a part of the file will be available.",
+                                data.storageFile.getPath());
                     }
+                    JOptionPane.showMessageDialog(null, msg);
                 }
-            };
-        } catch (SAXException e) {
-            e.printStackTrace();
-            throw new IOException(tr("Parsing data for layer ''{0}'' failed", gpxLayerName));
-        }
-        return data;
+            }
+        };
+        return result;
     }
 }
Index: core/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
===================================================================
--- core/src/org/openstreetmap/josm/io/OsmServerLocationReader.java	(revision 5476)
+++ core/src/org/openstreetmap/josm/io/OsmServerLocationReader.java	(working copy)
@@ -16,7 +16,7 @@
 public class OsmServerLocationReader extends OsmServerReader {
 
     protected final String url;
-
+    
     public OsmServerLocationReader(String url) {
         this.url = url;
     }
@@ -165,7 +165,7 @@
                     return null;
                 progressMonitor.subTask(tr("Downloading OSM data..."));
                 GpxReader reader = new GpxReader(in);
-                reader.parse(false);
+                gpxParsedProperly = reader.parse(false);
                 GpxData result = reader.data;
                 result.fromServer = true;
                 return result;
Index: core/src/org/openstreetmap/josm/io/OsmServerReader.java
===================================================================
--- core/src/org/openstreetmap/josm/io/OsmServerReader.java	(revision 5476)
+++ core/src/org/openstreetmap/josm/io/OsmServerReader.java	(working copy)
@@ -31,6 +31,7 @@
 public abstract class OsmServerReader extends OsmConnection {
     private OsmApi api = OsmApi.getOsmApi();
     private boolean doAuthenticate = false;
+    protected boolean gpxParsedProperly;
 
     /**
      * Open a connection to the given url and return a reader on the input stream
@@ -192,4 +193,13 @@
     public void setDoAuthenticate(boolean doAuthenticate) {
         this.doAuthenticate = doAuthenticate;
     }
+    
+    /**
+     * Determines if the GPX data has been parsed properly.
+     * @return true if the GPX data has been parsed properly, false otherwise
+     * @see GpxReader#parse
+     */
+    public final boolean isGpxParsedProperly() {
+        return gpxParsedProperly;
+    }
 }
