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


Ignore:
Timestamp:
2013-10-02T01:03:42+02:00 (11 years ago)
Author:
Don-vip
Message:

Sonar/Findbugs - Avoid Throwing Null Pointer Exception

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r6265 r6287  
    121121            try {
    122122                addRecursiveFiles(files, selection);
    123             } catch(NullPointerException npe) {
    124                 rememberError(tr("One of the selected files was null"));
     123            } catch (IllegalStateException e) {
     124                rememberError(e.getMessage());
    125125            }
    126126
     
    209209            }
    210210
    211             if (nullFile)
    212                 throw new NullPointerException();
     211            if (nullFile) {
     212                throw new IllegalStateException(tr("One of the selected files was null"));
     213            }
    213214        }
    214215
  • trunk/src/org/openstreetmap/josm/io/NmeaReader.java

    r6248 r6287  
    1 //License: GPL. Copyright 2008 by Christoph Brill
    2 
     1//License: GPL. See README for details.
    32package org.openstreetmap.josm.io;
    43
    54import java.io.BufferedReader;
    65import java.io.File;
    7 import java.io.IOException;
    86import java.io.InputStream;
    97import java.io.InputStreamReader;
     
    1513import java.util.Date;
    1614
     15import org.openstreetmap.josm.Main;
    1716import org.openstreetmap.josm.data.coor.LatLon;
    1817import org.openstreetmap.josm.data.gpx.GpxData;
     
    196195                int c = rd.read();
    197196                if(c=='$') {
    198                     ParseNMEASentence(sb.toString(), ps);
     197                    parseNMEASentence(sb.toString(), ps);
    199198                    sb.delete(0, sb.length());
    200199                    sb.append('$');
    201200                } else if(c == -1) {
    202201                    // EOF: add last WayPoint if it works out
    203                     ParseNMEASentence(sb.toString(),ps);
     202                    parseNMEASentence(sb.toString(),ps);
    204203                    break;
    205204                } else {
     
    210209            data.tracks.add(new ImmutableGpxTrack(currentTrack, Collections.<String, Object>emptyMap()));
    211210
    212         } catch (IOException e) {
    213             // TODO tell user about the problem?
     211        } catch (Exception e) {
     212            Main.warn(e);
    214213        } finally {
    215214            Utils.close(rd);
     
    233232    // in the collection in the NMEAParserState object.
    234233    // Returns true if the input made sence, false otherwise.
    235     private boolean ParseNMEASentence(String s, NMEAParserState ps) {
     234    private boolean parseNMEASentence(String s, NMEAParserState ps) throws IllegalDataException {
    236235        try {
    237             if (s.isEmpty())
    238                 throw new NullPointerException();
     236            if (s.isEmpty()) {
     237                throw new IllegalArgumentException("s is empty");
     238            }
    239239
    240240            // checksum check:
     
    274274                        e[GPGGA.LONGITUDE.position]
    275275                );
    276                 if(latLon==null)
    277                     throw new NullPointerException(); // malformed
    278 
    279                 if((latLon.lat()==0.0) && (latLon.lon()==0.0)) {
     276                if (latLon==null) {
     277                    throw new IllegalDataException("Malformed lat/lon");
     278                }
     279
     280                if ((latLon.lat()==0.0) && (latLon.lon()==0.0)) {
    280281                    ps.zero_coord++;
    281282                    return false;
Note: See TracChangeset for help on using the changeset viewer.