Changeset 11486 in josm


Ignore:
Timestamp:
2017-01-22T19:14:12+01:00 (11 months ago)
Author:
Don-vip
Message:

fix #14275 - robustness against invalid timestamps in GPX files

Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ConvertToDataLayerAction.java

    r11334 r11486  
    3737import org.openstreetmap.josm.tools.GBC;
    3838import org.openstreetmap.josm.tools.ImageProvider;
     39import org.openstreetmap.josm.tools.UncheckedParseException;
    3940import org.openstreetmap.josm.tools.date.DateUtils;
    4041
     
    4445 */
    4546public abstract class ConvertToDataLayerAction<T extends Layer> extends AbstractAction {
     47    /** source layer */
    4648    protected final transient T layer;
    4749
     50    /**
     51     * Constructs a new {@code ConvertToDataLayerAction}
     52     * @param layer source layer
     53     */
    4854    protected ConvertToDataLayerAction(final T layer) {
    4955        super(tr("Convert to data layer"), ImageProvider.get("converttoosm"));
     
    7581                        String timestr = p.getString(GpxConstants.PT_TIME);
    7682                        if (timestr != null) {
    77                             n.setTimestamp(DateUtils.fromString(timestr));
     83                            try {
     84                                n.setTimestamp(DateUtils.fromString(timestr));
     85                            } catch (UncheckedParseException e) {
     86                                Main.warn(e, false);
     87                            }
    7888                        }
    7989                        ds.addPrimitive(n);
     
    151161        }
    152162        final DataSet ds = convert();
    153         final OsmDataLayer layer = new OsmDataLayer(ds, tr("Converted from: {0}", this.layer.getName()), null);
    154         if (this.layer.getAssociatedFile() != null) {
    155             layer.setAssociatedFile(new File(this.layer.getAssociatedFile().getParentFile(), this.layer.getAssociatedFile().getName() + ".osm"));
     163        final OsmDataLayer osmLayer = new OsmDataLayer(ds, tr("Converted from: {0}", layer.getName()), null);
     164        if (layer.getAssociatedFile() != null) {
     165            osmLayer.setAssociatedFile(new File(layer.getAssociatedFile().getParentFile(), layer.getAssociatedFile().getName() + ".osm"));
    156166        }
    157         layer.setUploadDiscouraged(true);
    158         Main.getLayerManager().addLayer(layer);
    159         Main.getLayerManager().removeLayer(this.layer);
     167        osmLayer.setUploadDiscouraged(true);
     168        Main.getLayerManager().addLayer(osmLayer);
     169        Main.getLayerManager().removeLayer(layer);
    160170    }
    161171}
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/ConvertToDataLayerActionTest.java

    r11094 r11486  
    33
    44import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertNotNull;
     6
     7import java.io.IOException;
    58
    69import org.junit.BeforeClass;
     
    1316import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
    1417import org.openstreetmap.josm.io.GpxReaderTest;
     18import org.xml.sax.SAXException;
    1519
    1620/**
     
    4044                osm.getNodes().iterator().next().getKeys());
    4145    }
     46
     47    /**
     48     * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/14275">#14275</a>
     49     * @throws IOException if an error occurs during reading
     50     * @throws SAXException if any XML error occurs
     51     */
     52    @Test
     53    public void testTicket14275() throws IOException, SAXException {
     54        assertNotNull(GpxReaderTest.parseGpxData(TestUtils.getRegressionDataFile(14275, "1485101437.8189685.gpx")));
     55    }
    4256}
  • trunk/test/unit/org/openstreetmap/josm/tools/date/DateUtilsTest.java

    r11036 r11486  
    117117     */
    118118    @Test
    119     public void testFromDate() throws Exception {
     119    public void testFromDate() {
    120120        assertEquals("1970-01-01T00:00:00Z", DateUtils.fromDate(new Date(0)));
    121121        assertEquals("1970-01-01T00:00:00.1Z", DateUtils.fromDate(new Date(100)));
Note: See TracChangeset for help on using the changeset viewer.