Index: trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java	(revision 2794)
+++ trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java	(revision 2795)
@@ -79,4 +79,8 @@
     }
 
+    public boolean isEmpty() {
+        return !hasRoutePoints() && !hasTrackPoints() && waypoints.isEmpty();
+    }
+
     // FIXME might perhaps use visitor pattern?
     public Bounds recalculateBounds() {
Index: trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java	(revision 2794)
+++ trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java	(revision 2795)
@@ -179,5 +179,7 @@
                         iStream = new FileInputStream(sel);
                     }
-                    data = new GpxReader(iStream, sel).data;
+                    GpxReader reader = new GpxReader(iStream);
+                    reader.parse(false);
+                    data = reader.data;
                     data.storageFile = sel;
 
@@ -874,5 +876,5 @@
 
                     tfTimezone.setText(formatTimezone(timezone));
-                    tfOffset.setText(Long.toString(delta + dayOffset*24*60*60l));    // add the day offset to the offset field
+                    tfOffset.setText(Long.toString(delta + 24*60*60L*dayOffset));    // add the day offset to the offset field
 
                     tfTimezone.getDocument().addDocumentListener(statusBarListener);
Index: trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java	(revision 2794)
+++ trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java	(revision 2795)
@@ -51,5 +51,7 @@
                 }
                 progressMonitor.setTicks(0);
-                GpxData currentGpx = new GpxReader(in, null).data;
+                GpxReader reader = new GpxReader(in);
+                reader.parse(false);
+                GpxData currentGpx = reader.data;
                 if (result == null) {
                     result = currentGpx;
Index: trunk/src/org/openstreetmap/josm/io/GpxImporter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/GpxImporter.java	(revision 2794)
+++ trunk/src/org/openstreetmap/josm/io/GpxImporter.java	(revision 2795)
@@ -11,4 +11,5 @@
 import java.util.zip.GZIPInputStream;
 
+import javax.swing.JOptionPane;
 import javax.swing.SwingUtilities;
 
@@ -45,5 +46,6 @@
                 }
             }
-            final GpxReader r = new GpxReader(is, file.getAbsoluteFile().getParentFile());
+            final GpxReader r = new GpxReader(is);
+            final boolean parsedProperly = r.parse(true);
             r.data.storageFile = file;
             final GpxLayer gpxLayer = new GpxLayer(r.data, fn, true);
@@ -61,4 +63,7 @@
                             Main.main.addLayer(ml);
                         }
+                    }
+                    if (!parsedProperly) {
+                        JOptionPane.showMessageDialog(null, tr("Error occured while parsing gpx file {0}. Only part of the file will be available", file.getName()));
                     }
                 }
Index: trunk/src/org/openstreetmap/josm/io/GpxReader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/GpxReader.java	(revision 2794)
+++ trunk/src/org/openstreetmap/josm/io/GpxReader.java	(revision 2795)
@@ -6,5 +6,4 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -13,4 +12,5 @@
 import java.util.Collection;
 import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 import java.util.Stack;
@@ -41,5 +41,6 @@
      */
     public GpxData data;
-    public enum State { init, metadata, wpt, rte, trk, ext, author, link, trkseg, copyright}
+    private enum State { init, metadata, wpt, rte, trk, ext, author, link, trkseg, copyright}
+    private InputSource inputSource;
 
     private class Parser extends DefaultHandler {
@@ -55,4 +56,5 @@
         private GpxLink currentLink;
         private Stack<State> states;
+        private final Stack<String> elements = new Stack<String>();
 
         private StringBuffer accumulator = new StringBuffer();
@@ -81,4 +83,5 @@
 
         @Override public void startElement(String namespaceURI, String qName, String rqName, Attributes atts) throws SAXException {
+            elements.push(qName);
             switch(currentState) {
             case init:
@@ -211,4 +214,5 @@
         @SuppressWarnings("unchecked")
         @Override public void endElement(String namespaceURI, String qName, String rqName) {
+            elements.pop();
             switch (currentState) {
             case metadata:
@@ -333,4 +337,12 @@
             data = currentData;
         }
+
+        public void tryToFinish() throws SAXException {
+            List<String> remainingElements = new ArrayList<String>(elements);
+            for (int i=remainingElements.size() - 1; i >= 0; i--) {
+                endElement(null, remainingElements.get(i), null);
+            }
+            endDocument();
+        }
     }
 
@@ -338,15 +350,30 @@
      * Parse the input stream and store the result in trackData and markerData
      *
-     * @param relativeMarkerPath The directory to use as relative path for all &lt;wpt&gt;
-     *    marker tags. Maybe <code>null</code>, in which case no relative urls are constructed for the markers.
      */
-    public GpxReader(InputStream source, File relativeMarkerPath) throws SAXException, IOException {
-
+    public GpxReader(InputStream source) throws IOException {
+        this.inputSource = new InputSource(new InputStreamReader(source, "UTF-8"));
+    }
+
+    /**
+     * 
+     * @return True if file was properly parsed, false if there was error during parsing but some data were parsed anyway
+     * @throws SAXException
+     * @throws IOException
+     */
+    public boolean parse(boolean tryToFinish) throws SAXException, IOException {
         Parser parser = new Parser();
-        InputSource inputSource = new InputSource(new InputStreamReader(source, "UTF-8"));
         try {
             SAXParserFactory factory = SAXParserFactory.newInstance();
             factory.setNamespaceAware(true);
             factory.newSAXParser().parse(inputSource, parser);
+            return true;
+        } catch (SAXException e) {
+            if (tryToFinish) {
+                parser.tryToFinish();
+                if (parser.currentData.isEmpty())
+                    throw e;
+                return false;
+            } else
+                throw e;
         } catch (ParserConfigurationException e) {
             e.printStackTrace(); // broken SAXException chaining
