Changeset 12087 in josm


Ignore:
Timestamp:
2017-05-08T15:53:13+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #14754 - avoid silent failure with invalid lat/lon coordinates in .osm file

Location:
trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r11919 r12087  
    218218        String lat = parser.getAttributeValue(null, "lat");
    219219        String lon = parser.getAttributeValue(null, "lon");
     220        LatLon ll = null;
    220221        if (lat != null && lon != null) {
    221             nd.setCoor(new LatLon(Double.parseDouble(lat), Double.parseDouble(lon)));
     222            ll = new LatLon(Double.parseDouble(lat), Double.parseDouble(lon));
     223            nd.setCoor(ll);
    222224        }
    223225        readCommon(nd);
     226        if (ll != null && !ll.isValid()) {
     227            throwException(tr("Illegal value for attributes ''lat'', ''lon'' on node with ID {0}. Got ''{1}'', ''{2}''.",
     228                    Long.toString(nd.getId()), lat, lon));
     229        }
    224230        Node n = new Node(nd.getId(), nd.getVersion());
    225231        n.setVisible(nd.isVisible());
  • trunk/test/unit/org/openstreetmap/josm/io/OsmReaderTest.java

    r11435 r12087  
    55import static org.junit.Assert.assertNull;
    66import static org.junit.Assert.assertTrue;
     7import static org.junit.Assert.fail;
    78
    89import java.io.InputStream;
     
    3132        }
    3233    }
     34
     35    /**
     36     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/14754">Bug #14754</a>.
     37     * @throws Exception if any error occurs
     38     */
     39    @Test
     40    public void testTicket14754() throws Exception {
     41        try (InputStream in = TestUtils.getRegressionDataStream(14754, "malformed_for_14754.osm")) {
     42            OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE);
     43            fail("should throw exception");
     44        } catch (IllegalDataException e) {
     45            assertEquals("Illegal value for attributes 'lat', 'lon' on node with ID 1425146006." +
     46                    " Got '550.3311950157', '10.49428298298'." +
     47                    " (at line 5, column 179). 578 bytes have been read", e.getMessage());
     48        }
     49    }
    3350}
Note: See TracChangeset for help on using the changeset viewer.