Changeset 1049 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2008-10-21T20:49:20+02:00 (16 years ago)
Author:
cbrill
Message:

Fix bug #1626 (incomplete NMEA files cause crashes)

File:
1 edited

Legend:

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

    r999 r1049  
    99import java.io.InputStreamReader;
    1010import java.util.ArrayList;
     11import java.util.Arrays;
    1112import java.util.Collection;
    1213
     
    140141                                // XXX: No need for it: String checksum = nmeaAndChecksum[1];
    141142                                String[] e = nmea.split(",");
     143                                if (e.length == 0) {
     144                                    continue;
     145                                }
    142146                                if (NMEA_TYPE.GPRMC.equals(e[TYPE])) {
    143147                                        LatLon latLon = parseLatLon(e);
     
    157161
    158162        private LatLon parseLatLon(String[] e) throws NumberFormatException {
    159                 String widthNorth = e[GPRMC.WIDTH_NORTH.position].trim();
     163            // If the array looks bogus don't try to get valuable information from it
     164            if (e.length != 13) {
     165                return null;
     166            }
     167        String widthNorth = e[GPRMC.WIDTH_NORTH.position].trim();
    160168                String lengthEast = e[GPRMC.LENGTH_EAST.position].trim();
    161169                if ("".equals(widthNorth) || "".equals(lengthEast)) {
Note: See TracChangeset for help on using the changeset viewer.