Changeset 11486 in josm for trunk/src


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

fix #14275 - robustness against invalid timestamps in GPX files

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.