Ignore:
Timestamp:
2016-04-02T15:00:31+02:00 (8 years ago)
Author:
donvip
Message:

fix #josm12714 - robustness against invalid SHP files

Location:
applications/editors/josm/plugins/opendata
Files:
6 added
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeographicReader.java

    r31655 r32139  
    101101
    102102    protected Node createOrGetNode(Point p, String ele) throws MismatchedDimensionException, TransformException {
     103        if (!p.isValid()) {
     104            throw new IllegalArgumentException("Invalid point: " + p);
     105        }
    103106        Point p2 = (Point) JTS.transform(p, transform);
    104107        LatLon key = new LatLon(p2.getY(), p2.getX());
     
    157160                try {
    158161                    tempWay.addNode(createOrGetNode(ls.getPointN(i)));
    159                 } catch (Exception e) {
    160                     Main.error(e.getMessage());
     162                } catch (TransformException | IllegalArgumentException e) {
     163                    Main.error("Exception for " + ls + ": " + e.getClass().getName() + ": " + e.getMessage());
    161164                }
    162165            }
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java

    r31655 r32139  
    241241                        }
    242242                    }
    243                 } catch (Throwable e) {
    244                     e.printStackTrace();
    245243                } finally {
    246244                    iterator.close();
     
    254252            e.printStackTrace();
    255253            throw e;
    256         } catch (Throwable t) {
    257             t.printStackTrace();
    258             throw new IOException(t);
     254        } catch (Exception e) {
     255            e.printStackTrace();
     256            throw new IOException(e);
    259257        }
    260258        return ds;
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/layers/OdDataLayer.java

    r31116 r32139  
    1010
    1111import javax.swing.Action;
    12 import javax.swing.Icon;
    1312
    1413import org.openstreetmap.josm.Main;
    1514import org.openstreetmap.josm.data.Bounds;
     15import org.openstreetmap.josm.data.coor.LatLon;
    1616import org.openstreetmap.josm.data.osm.DataSet;
    1717import org.openstreetmap.josm.data.osm.Node;
     
    2020import org.openstreetmap.josm.gui.layer.Layer;
    2121import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    22 import org.openstreetmap.josm.tools.ImageProvider;
    2322import org.openstreetmap.josm.plugins.opendata.core.OdConstants;
    2423import org.openstreetmap.josm.plugins.opendata.core.actions.OpenLinkAction;
     
    2827import org.openstreetmap.josm.plugins.opendata.core.licenses.License;
    2928import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils;
     29import org.openstreetmap.josm.tools.ImageProvider;
    3030
    3131public class OdDataLayer extends OsmDataLayer implements OdLayer, LayerChangeListener {
     
    4343        this.handler = handler;
    4444        for (Node node : data.getNodes()) {
    45             if (this.bounds == null) {
    46                 this.bounds = new Bounds(node.getCoor());
    47             } else {
    48                 this.bounds.extend(node.getCoor());
     45            LatLon ll = node.getCoor();
     46            if (ll != null) {
     47                if (this.bounds == null) {
     48                    this.bounds = new Bounds(ll);
     49                } else {
     50                    this.bounds.extend(ll);
     51                }
    4952            }
    5053        }
  • applications/editors/josm/plugins/opendata/test/unit/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReaderTest.java

    r30573 r32139  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.opendata.core.io.geographic;
     3
     4import static org.junit.Assert.assertNotNull;
    35
    46import java.io.File;
     
    1416import org.openstreetmap.josm.JOSMFixture;
    1517import org.openstreetmap.josm.TestUtils;
     18import org.openstreetmap.josm.data.osm.Node;
    1619import org.openstreetmap.josm.plugins.opendata.core.io.NonRegFunctionalTests;
    1720
     
    2831        JOSMFixture.createUnitTestFixture().init();
    2932    }
    30    
     33
     34    /**
     35     * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/12714">#12714/a>
     36     * @throws IOException if an error occurs during reading
     37     */
     38    @Test
     39    public void testTicket12714() throws IOException, XMLStreamException, FactoryConfigurationError {
     40        File file = new File(TestUtils.getRegressionDataFile(12714, "linhas.shp"));
     41        try (InputStream is = new FileInputStream(file)) {
     42            for (Node n : ShpReader.parseDataSet(is, file, null, null).getNodes()) {
     43                assertNotNull(n.toString(), n.getCoor());
     44            }
     45        }
     46    }
     47
    3148    /**
    3249     * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/10214">#10214</a>
Note: See TracChangeset for help on using the changeset viewer.