Index: /trunk/src/org/openstreetmap/josm/data/gpx/GpxExtensionCollection.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/gpx/GpxExtensionCollection.java	(revision 17983)
+++ /trunk/src/org/openstreetmap/josm/data/gpx/GpxExtensionCollection.java	(revision 17984)
@@ -10,6 +10,6 @@
 import java.util.stream.Stream;
 
-import org.apache.commons.jcs3.access.exception.InvalidArgumentException;
 import org.openstreetmap.josm.io.GpxReader;
+import org.openstreetmap.josm.tools.Logging;
 import org.xml.sax.Attributes;
 
@@ -61,18 +61,19 @@
     /**
      * Sets the value for the last child and pops it from the stack, so the next one will be added to its parent.
-     * The qualified name is verified.
+     * A warning is issued if the qualified name does not equal the currently opened child.
      * @param qName the qualified name
      * @param value the value
      */
     public void closeChild(String qName, String value) {
-        if (childStack == null || childStack.isEmpty())
-            throw new InvalidArgumentException("Can't close child " + qName + ", no element in stack.");
+        if (childStack == null || childStack.isEmpty()) {
+            Logging.warn("Can''t close child ''{0}'', no element in stack.", qName);
+            return;
+		}
 
         GpxExtension child = childStack.pop();
-
         String childQN = child.getQualifiedName();
 
         if (!childQN.equals(qName))
-            throw new InvalidArgumentException("Can't close child " + qName + ", must close " + childQN + " first.");
+            Logging.warn("Couldn''t close child ''{0}'', closed ''{1}'' instead.", qName, childQN);
 
         child.setValue(value);
Index: /trunk/src/org/openstreetmap/josm/io/GpxReader.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/GpxReader.java	(revision 17983)
+++ /trunk/src/org/openstreetmap/josm/io/GpxReader.java	(revision 17984)
@@ -84,5 +84,5 @@
         private GpxExtensionCollection currentTrackExtensionCollection;
         private Stack<State> states;
-        private final Stack<String> elements = new Stack<>();
+        private final Stack<String[]> elements = new Stack<>();
 
         private StringBuilder accumulator = new StringBuilder();
@@ -133,5 +133,5 @@
         @Override
         public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
-            elements.push(localName);
+            elements.push(new String[] { namespaceURI, localName, qName });
             switch(currentState) {
             case INIT:
@@ -610,7 +610,8 @@
 
         void tryToFinish() throws SAXException {
-            List<String> remainingElements = new ArrayList<>(elements);
+            List<String[]> remainingElements = new ArrayList<>(elements);
             for (int i = remainingElements.size() - 1; i >= 0; i--) {
-                endElement(null, remainingElements.get(i), remainingElements.get(i));
+                String[] e = remainingElements.get(i);
+                endElement(e[0], e[1], e[2]);
             }
             endDocument();
Index: /trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxExtensionCollectionTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxExtensionCollectionTest.java	(revision 17984)
+++ /trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxExtensionCollectionTest.java	(revision 17984)
@@ -0,0 +1,55 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.data.gpx;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.openstreetmap.josm.testutils.JOSMTestRules;
+import org.openstreetmap.josm.tools.Logging;
+import org.xml.sax.helpers.AttributesImpl;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+/**
+ * Unit tests of {@link GpxExtensionCollection}.
+ */
+class GpxExtensionCollectionTest {
+
+    /**
+     * Setup test.
+     */
+    @RegisterExtension
+    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
+    public JOSMTestRules test = new JOSMTestRules();
+
+    @BeforeEach
+    void before() {
+        Logging.clearLastErrorAndWarnings();
+    }
+
+    @Test
+    void testCloseChildWithEmptyStack() {
+        GpxExtensionCollection collection = new GpxExtensionCollection();
+        collection.closeChild("foo", "bar");
+        collection.closeChild("foo", "bar");
+        List<String> logs = Logging.getLastErrorAndWarnings();
+        assertEquals(2, logs.size());
+        assertTrue(logs.get(0).endsWith("W: Can't close child 'foo', no element in stack."));
+        assertTrue(logs.get(1).endsWith("W: Can't close child 'foo', no element in stack."));
+    }
+
+    @Test
+    void testCloseChildWithAnotherInStack() {
+        GpxExtensionCollection collection = new GpxExtensionCollection();
+        collection.openChild(null, "baz", new AttributesImpl());
+        collection.closeChild("foo", "bar");
+        List<String> logs = Logging.getLastErrorAndWarnings();
+        assertEquals(1, logs.size());
+        assertTrue(logs.get(0).endsWith("W: Couldn't close child 'foo', closed 'baz' instead."));
+    }
+}
