Changeset 12422 in josm


Ignore:
Timestamp:
2017-06-22T01:07:31+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #14924 - fix NPE when reading NMEA files starting with a (0,0) coordinate followed by a VTG sentence

Location:
trunk
Files:
3 added
2 edited

Legend:

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

    r12421 r12422  
    342342                    // other values than (T)rue are ignored
    343343                    accu = e[VTG.COURSE.position];
    344                     if (!accu.isEmpty()) {
     344                    if (!accu.isEmpty() && currentwp != null) {
    345345                        Double.parseDouble(accu);
    346346                        currentwp.put("course", accu);
     
    351351                if (accu.startsWith("K")) {
    352352                    accu = e[VTG.SPEED_KMH.position];
    353                     if (!accu.isEmpty()) {
     353                    if (!accu.isEmpty() && currentwp != null) {
    354354                        double speed = Double.parseDouble(accu);
    355355                        speed /= 3.6; // speed in m/s
  • trunk/test/unit/org/openstreetmap/josm/io/nmea/NmeaReaderTest.java

    r12421 r12422  
    7676        assertEquals(numCoor, in.getNumberOfCoordinates());
    7777        assertEquals(0, in.getParserMalformed());
    78         assertEquals(in.data.dataSources, gpx.dataSources);
     78        assertEquals(gpx.dataSources, in.data.dataSources);
    7979        assertEquals(1, gpx.tracks.size());
    8080        assertEquals(1, in.data.tracks.size());
     
    8282        GpxTrack nmeaTrack = in.data.tracks.iterator().next();
    8383        assertEquals(gpxTrack.getBounds(), nmeaTrack.getBounds());
    84         assertEquals(1, gpxTrack.getSegments().size());
    85         assertEquals(1, nmeaTrack.getSegments().size());
    86         GpxTrackSegment gpxSeg = gpxTrack.getSegments().iterator().next();
    87         GpxTrackSegment nmeaSeg = nmeaTrack.getSegments().iterator().next();
    88         assertEquals(gpxSeg.getBounds(), nmeaSeg.getBounds());
    89         assertEquals(numCoor, gpxSeg.getWayPoints().size());
    90         assertEquals(numCoor, nmeaSeg.getWayPoints().size());
    91         WayPoint gpxWpt = gpxSeg.getWayPoints().iterator().next();
    92         WayPoint nmeaWpt = nmeaSeg.getWayPoints().iterator().next();
    93         assertEquals(gpxWpt.getCoor().getRoundedToOsmPrecision(), nmeaWpt.getCoor().getRoundedToOsmPrecision());
     84        int nTracks = gpxTrack.getSegments().size();
     85        assertEquals(nTracks, nmeaTrack.getSegments().size());
     86        if (nTracks > 0) {
     87            GpxTrackSegment gpxSeg = gpxTrack.getSegments().iterator().next();
     88            GpxTrackSegment nmeaSeg = nmeaTrack.getSegments().iterator().next();
     89            assertEquals(gpxSeg.getBounds(), nmeaSeg.getBounds());
     90            assertEquals(numCoor, gpxSeg.getWayPoints().size());
     91            assertEquals(numCoor, nmeaSeg.getWayPoints().size());
     92            WayPoint gpxWpt = gpxSeg.getWayPoints().iterator().next();
     93            WayPoint nmeaWpt = nmeaSeg.getWayPoints().iterator().next();
     94            assertEquals(gpxWpt.getCoor().getRoundedToOsmPrecision(), nmeaWpt.getCoor().getRoundedToOsmPrecision());
     95        }
    9496    }
    9597
     
    133135        compareWithReference(2147, "WG20080203171807.log", 487);
    134136    }
     137
     138    /**
     139     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/14924">Bug #14924</a>.
     140     * @throws Exception if an error occurs
     141     */
     142    @Test
     143    public void testTicket14924() throws Exception {
     144        compareWithReference(14924, "input", 0);
     145    }
    135146}
Note: See TracChangeset for help on using the changeset viewer.