Changeset 11397 in josm


Ignore:
Timestamp:
2016-12-14T15:50:53+01:00 (7 years ago)
Author:
Don-vip
Message:

sonar - squid:S2259 - Null pointers should not be dereferenced

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    r10875 r11397  
    499499                    }
    500500                }
    501             } else {
     501            } else if (bestMovement != null) {
    502502                if (mode == Mode.extrude || mode == Mode.create_new) {
    503503                    //nothing here
     
    897897        // set neighboring segments
    898898        Node prevNode = getPreviousNode(selectedSegment.lowerIndex);
    899         EastNorth prevNodeEn = prevNode.getEastNorth();
    900         dualAlignSegment1 = new ReferenceSegment(new EastNorth(
    901             initialN1en.getX() - prevNodeEn.getX(),
    902             initialN1en.getY() - prevNodeEn.getY()
    903             ), initialN1en, prevNodeEn, false);
     899        if (prevNode != null) {
     900            EastNorth prevNodeEn = prevNode.getEastNorth();
     901            dualAlignSegment1 = new ReferenceSegment(new EastNorth(
     902                initialN1en.getX() - prevNodeEn.getX(),
     903                initialN1en.getY() - prevNodeEn.getY()
     904                ), initialN1en, prevNodeEn, false);
     905        }
    904906
    905907        Node nextNode = getNextNode(selectedSegment.lowerIndex + 1);
    906         EastNorth nextNodeEn = nextNode.getEastNorth();
    907         dualAlignSegment2 = new ReferenceSegment(new EastNorth(
    908             initialN2en.getX() - nextNodeEn.getX(),
    909             initialN2en.getY() - nextNodeEn.getY()
    910             ), initialN2en, nextNodeEn, false);
     908        if (nextNode != null) {
     909            EastNorth nextNodeEn = nextNode.getEastNorth();
     910            dualAlignSegment2 = new ReferenceSegment(new EastNorth(
     911                initialN2en.getX() - nextNodeEn.getX(),
     912                initialN2en.getY() - nextNodeEn.getY()
     913                ), initialN2en, nextNodeEn, false);
     914        }
    911915    }
    912916
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java

    r11331 r11397  
    213213     */
    214214    protected String getServerKey() {
    215         return getUrlNoException().getHost();
     215        try {
     216            return getUrl().getHost();
     217        } catch (IOException e) {
     218            Main.trace(e);
     219            return null;
     220        }
    216221    }
    217222
     
    255260        Set<ICachedLoaderListener> listeners;
    256261        synchronized (inProgress) {
    257             listeners = inProgress.remove(getUrlNoException().toString());
     262            try {
     263                listeners = inProgress.remove(getUrl().toString());
     264            } catch (IOException e) {
     265                listeners = null;
     266                Main.trace(e);
     267            }
    258268        }
    259269        if (listeners == null) {
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r11374 r11397  
    1515import java.util.List;
    1616import java.util.Map;
     17import java.util.Objects;
    1718import java.util.Set;
    1819import java.util.concurrent.CopyOnWriteArrayList;
     
    499500     */
    500501    public void addPrimitive(OsmPrimitive primitive) {
     502        Objects.requireNonNull(primitive, "primitive");
    501503        beginUpdate();
    502504        try {
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r11383 r11397  
    22package org.openstreetmap.josm.data.osm;
    33
     4import java.awt.geom.Area;
    45import java.util.Collection;
    56import java.util.Objects;
     
    420421    @Override
    421422    public boolean isOutsideDownloadArea() {
    422         return !isNewOrUndeleted() && getDataSet() != null && getDataSet().getDataSourceArea() != null
    423                 && getCoor() != null && !getCoor().isIn(getDataSet().getDataSourceArea());
     423        if (isNewOrUndeleted() || getDataSet() == null)
     424            return false;
     425        Area area = getDataSet().getDataSourceArea();
     426        if (area == null)
     427            return false;
     428        LatLon coor = getCoor();
     429        return coor != null && !coor.isIn(area);
    424430    }
    425431}
  • trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java

    r11277 r11397  
    116116                if (idx == -1)
    117117                    return this;
    118                 return getChild(idx).findBucket(bbox);
     118                QBLevel<T> child = getChild(idx);
     119                if (child == null)
     120                    return this;
     121                return child.findBucket(bbox);
    119122            }
    120123        }
     
    140143        /*
    141144         * There is a race between this and qb.nextContentNode().
    142          * If nextContentNode() runs into this bucket, it may
    143          * attempt to null out 'children' because it thinks this
    144          * is a dead end.
     145         * If nextContentNode() runs into this bucket, it may attempt to null out 'children' because it thinks this is a dead end.
    145146         */
    146147        void doSplit() {
     
    153154                    doAddContent(o);
    154155                } else {
    155                     getChild(idx).doAdd(o);
     156                    QBLevel<T> child = getChild(idx);
     157                    if (child != null)
     158                        child.doAdd(o);
    156159                }
    157160            }
  • trunk/src/org/openstreetmap/josm/data/osm/WaySegment.java

    r11227 r11397  
    9494    @Override
    9595    public int compareTo(WaySegment o) {
    96         return equals(o) ? 0 : toWay().compareTo(o.toWay());
     96        return o == null ? -1 : (equals(o) ? 0 : toWay().compareTo(o.toWay()));
    9797    }
    9898
  • trunk/src/org/openstreetmap/josm/data/validation/routines/DomainValidator.java

    r11379 r11397  
    221221     */
    222222    public boolean isValidInfrastructureTld(String iTld) {
     223        if (iTld == null) return false;
    223224        final String key = chompLeadingDot(unicodeToASCII(iTld).toLowerCase(Locale.ENGLISH));
    224225        return arrayContains(INFRASTRUCTURE_TLDS, key);
     
    233234     */
    234235    public boolean isValidGenericTld(String gTld) {
     236        if (gTld == null) return false;
    235237        final String key = chompLeadingDot(unicodeToASCII(gTld).toLowerCase(Locale.ENGLISH));
    236238        return (arrayContains(GENERIC_TLDS, key) || arrayContains(genericTLDsPlus, key))
     
    246248     */
    247249    public boolean isValidCountryCodeTld(String ccTld) {
     250        if (ccTld == null) return false;
    248251        final String key = chompLeadingDot(unicodeToASCII(ccTld).toLowerCase(Locale.ENGLISH));
    249252        return (arrayContains(COUNTRY_CODE_TLDS, key) || arrayContains(countryCodeTLDsPlus, key))
     
    259262     */
    260263    public boolean isValidLocalTld(String lTld) {
     264        if (lTld == null) return false;
    261265        final String key = chompLeadingDot(unicodeToASCII(lTld).toLowerCase(Locale.ENGLISH));
    262266        return arrayContains(LOCAL_TLDS, key);
  • trunk/src/org/openstreetmap/josm/gui/help/HelpUtil.java

    r9320 r11397  
    6969    public static String getHelpTopicEditUrl(String absoluteHelpTopic) {
    7070        String topicUrl = getHelpTopicUrl(absoluteHelpTopic);
    71         topicUrl = topicUrl.replaceAll("#[^#]*$", ""); // remove optional fragment
     71        if (topicUrl != null)
     72            topicUrl = topicUrl.replaceAll("#[^#]*$", ""); // remove optional fragment
    7273        return topicUrl + "?action=edit";
    7374    }
     
    8485        if (topic == null)
    8586            return null;
    86         String pattern = "/[A-Z][a-z]{1,2}(_[A-Z]{2})?:" + getHelpTopicPrefix(LocaleType.ENGLISH).replaceAll("^\\/+", "");
     87        String topicPrefix = getHelpTopicPrefix(LocaleType.ENGLISH);
     88        if (topicPrefix != null)
     89            topicPrefix = topicPrefix.replaceAll("^\\/+", "");
     90        String pattern = "/[A-Z][a-z]{1,2}(_[A-Z]{2})?:" + topicPrefix;
    8791        if (url.matches(pattern)) {
    8892            return topic.substring(pattern.length());
     
    100104    public static String extractAbsoluteHelpTopic(String url) {
    101105        if (url == null || !url.startsWith(getWikiBaseHelpUrl())) return null;
    102         url = url.substring(getWikiBaseHelpUrl().length());
     106        String topic = url.substring(getWikiBaseHelpUrl().length());
    103107        String prefix = getHelpTopicPrefix(LocaleType.ENGLISH);
    104         if (url.startsWith(prefix))
    105             return url;
     108        if (prefix == null || topic.startsWith(prefix))
     109            return topic;
    106110
    107111        String pattern = "/[A-Z][a-z]{1,2}(_[A-Z]{2})?:" + prefix.replaceAll("^\\/+", "");
    108         if (url.matches(pattern))
    109             return url;
     112        if (topic.matches(pattern))
     113            return topic;
    110114
    111115        return null;
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java

    r11322 r11397  
    425425            switch (column) {
    426426            case VersionTableColumnModel.COL_VERSION:
    427                 return Long.toString(getPrimitive(row).getVersion());
     427                HistoryOsmPrimitive p1 = getPrimitive(row);
     428                if (p1 != null)
     429                    return Long.toString(p1.getVersion());
     430                return null;
    428431            case VersionTableColumnModel.COL_REFERENCE:
    429432                return isReferencePointInTime(row);
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r11383 r11397  
    504504                        if (e.hasThumbnail()) {
    505505                            Dimension d = scaledDimension(e.getThumbnail());
    506                             Rectangle target = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height);
    507                             if (clip.intersects(target)) {
    508                                 tempG.drawImage(e.getThumbnail(), target.x, target.y, target.width, target.height, null);
     506                            if (d != null) {
     507                                Rectangle target = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height);
     508                                if (clip.intersects(target)) {
     509                                    tempG.drawImage(e.getThumbnail(), target.x, target.y, target.width, target.height, null);
     510                                }
    509511                            }
    510512                        } else { // thumbnail not loaded yet
     
    540542                if (useThumbs && e.hasThumbnail()) {
    541543                    Dimension d = scaledDimension(e.getThumbnail());
    542                     imgWidth = d.width;
    543                     imgHeight = d.height;
     544                    if (d != null) {
     545                        imgWidth = d.width;
     546                        imgHeight = d.height;
     547                    } else {
     548                        imgWidth = -1;
     549                        imgHeight = -1;
     550                    }
    544551                } else {
    545552                    imgWidth = selectedIcon.getIconWidth();
     
    756763                if (useThumbs && img.hasThumbnail()) {
    757764                    Dimension d = scaledDimension(img.getThumbnail());
    758                     r = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height);
     765                    if (d != null)
     766                        r = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height);
     767                    else
     768                        r = null;
    759769                } else {
    760770                    r = new Rectangle(p.x - icon.getIconWidth() / 2,
     
    763773                                      icon.getIconHeight());
    764774                }
    765                 if (r.contains(evt.getPoint())) {
     775                if (r != null && r.contains(evt.getPoint())) {
    766776                    return img;
    767777                }
     
    861871                    if (useThumbs && e.hasThumbnail()) {
    862872                        Dimension d = scaledDimension(e.getThumbnail());
    863                         r = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height);
     873                        if (d != null)
     874                            r = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height);
     875                        else
     876                            r = null;
    864877                    } else {
    865878                        r = new Rectangle(p.x - icon.getIconWidth() / 2,
     
    868881                                icon.getIconHeight());
    869882                    }
    870                     if (r.contains(ev.getPoint())) {
     883                    if (r != null && r.contains(ev.getPoint())) {
    871884                        clearOtherCurrentPhotos();
    872885                        currentPhoto = i;
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java

    r11087 r11397  
    402402        // create a task for downloading plugins if the user has activated, yet not downloaded, new plugins
    403403        final PluginPreference preference = getPluginPreference();
    404         final Set<PluginInformation> toDownload = preference.getPluginsScheduledForUpdateOrDownload();
    405         final PluginDownloadTask task;
    406         if (toDownload != null && !toDownload.isEmpty()) {
    407             task = new PluginDownloadTask(this, toDownload, tr("Download plugins"));
    408         } else {
    409             task = null;
    410         }
    411 
    412         // this is the task which will run *after* the plugins are downloaded
    413         final Runnable continuation = new PluginDownloadAfterTask(preference, task, toDownload);
    414 
    415         if (task != null) {
    416             // if we have to launch a plugin download task we do it asynchronously, followed
    417             // by the remaining "save preferences" activites run on the Swing EDT.
    418             Main.worker.submit(task);
    419             Main.worker.submit(() -> SwingUtilities.invokeLater(continuation));
    420         } else {
    421             // no need for asynchronous activities. Simply run the remaining "save preference"
    422             // activities on this thread (we are already on the Swing EDT
    423             continuation.run();
     404        if (preference != null) {
     405            final Set<PluginInformation> toDownload = preference.getPluginsScheduledForUpdateOrDownload();
     406            final PluginDownloadTask task;
     407            if (toDownload != null && !toDownload.isEmpty()) {
     408                task = new PluginDownloadTask(this, toDownload, tr("Download plugins"));
     409            } else {
     410                task = null;
     411            }
     412
     413            // this is the task which will run *after* the plugins are downloaded
     414            final Runnable continuation = new PluginDownloadAfterTask(preference, task, toDownload);
     415
     416            if (task != null) {
     417                // if we have to launch a plugin download task we do it asynchronously, followed
     418                // by the remaining "save preferences" activites run on the Swing EDT.
     419                Main.worker.submit(task);
     420                Main.worker.submit(() -> SwingUtilities.invokeLater(continuation));
     421            } else {
     422                // no need for asynchronous activities. Simply run the remaining "save preference"
     423                // activities on this thread (we are already on the Swing EDT
     424                continuation.run();
     425            }
    424426        }
    425427    }
  • trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

    r11100 r11397  
    9494                // API 0.6 does not support requests crossing the 180th meridian, so make two requests
    9595                GpxData result = downloadRawGps(new Bounds(lat1, lon1, lat2, 180.0), progressMonitor);
    96                 result.mergeFrom(downloadRawGps(new Bounds(lat1, -180.0, lat2, lon2), progressMonitor));
     96                if (result != null)
     97                    result.mergeFrom(downloadRawGps(new Bounds(lat1, -180.0, lat2, lon2), progressMonitor));
    9798                return result;
    9899            } else {
  • trunk/src/org/openstreetmap/josm/io/GpxReader.java

    r10378 r11397  
    399399                } else if (currentState != State.LINK) {
    400400                    Map<String, Object> attr = getAttr();
    401                     if (!attr.containsKey(META_LINKS)) {
     401                    if (attr != null && !attr.containsKey(META_LINKS)) {
    402402                        attr.put(META_LINKS, new LinkedList<GpxLink>());
    403403                    }
    404                     ((Collection<GpxLink>) attr.get(META_LINKS)).add(currentLink);
     404                    if (attr != null)
     405                        ((Collection<GpxLink>) attr.get(META_LINKS)).add(currentLink);
    405406                }
    406407                break;
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r11345 r11397  
    891891            Map<String, PluginInformation> infos = loadLocallyAvailablePluginInformation(monitor.createSubTaskMonitor(1, false));
    892892            List<PluginInformation> ret = new LinkedList<>();
    893             for (Iterator<String> it = plugins.iterator(); it.hasNext();) {
    894                 String plugin = it.next();
    895                 if (infos.containsKey(plugin)) {
    896                     ret.add(infos.get(plugin));
    897                     it.remove();
     893            if (infos != null) {
     894                for (Iterator<String> it = plugins.iterator(); it.hasNext();) {
     895                    String plugin = it.next();
     896                    if (infos.containsKey(plugin)) {
     897                        ret.add(infos.get(plugin));
     898                        it.remove();
     899                    }
    898900                }
    899901            }
  • trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java

    r11100 r11397  
    124124     */
    125125    public static void play(URL url) throws Exception {
    126         AudioPlayer.getInstance().command.play(url, 0.0, 1.0);
     126        AudioPlayer instance = AudioPlayer.getInstance();
     127        if (instance != null)
     128            instance.command.play(url, 0.0, 1.0);
    127129    }
    128130
     
    134136     */
    135137    public static void play(URL url, double seconds) throws Exception {
    136         AudioPlayer.getInstance().command.play(url, seconds, 1.0);
     138        AudioPlayer instance = AudioPlayer.getInstance();
     139        if (instance != null)
     140            instance.command.play(url, seconds, 1.0);
    137141    }
    138142
     
    145149     */
    146150    public static void play(URL url, double seconds, double speed) throws Exception {
    147         AudioPlayer.getInstance().command.play(url, seconds, speed);
     151        AudioPlayer instance = AudioPlayer.getInstance();
     152        if (instance != null)
     153            instance.command.play(url, seconds, speed);
    148154    }
    149155
     
    153159     */
    154160    public static void pause() throws Exception {
    155         AudioPlayer.getInstance().command.pause();
     161        AudioPlayer instance = AudioPlayer.getInstance();
     162        if (instance != null)
     163            instance.command.pause();
    156164    }
    157165
     
    161169     */
    162170    public static URL url() {
    163         return AudioPlayer.getInstance().playingUrl;
     171        AudioPlayer instance = AudioPlayer.getInstance();
     172        return instance == null ? null : instance.playingUrl;
    164173    }
    165174
     
    169178     */
    170179    public static boolean paused() {
    171         return AudioPlayer.getInstance().state == State.PAUSED;
     180        AudioPlayer instance = AudioPlayer.getInstance();
     181        return instance == null ? false : (instance.state == State.PAUSED);
    172182    }
    173183
     
    177187     */
    178188    public static boolean playing() {
    179         return AudioPlayer.getInstance().state == State.PLAYING;
     189        AudioPlayer instance = AudioPlayer.getInstance();
     190        return instance == null ? false : (instance.state == State.PLAYING);
    180191    }
    181192
     
    185196     */
    186197    public static double position() {
    187         return AudioPlayer.getInstance().position;
     198        AudioPlayer instance = AudioPlayer.getInstance();
     199        return instance == null ? -1 : instance.position;
    188200    }
    189201
     
    193205     */
    194206    public static double speed() {
    195         return AudioPlayer.getInstance().speed;
     207        AudioPlayer instance = AudioPlayer.getInstance();
     208        return instance == null ? -1 : instance.speed;
    196209    }
    197210
  • trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java

    r10717 r11397  
    510510        return tr("<html>Failed to upload data to or download data from<br>" + "''{0}''<br>"
    511511                + "due to a problem with transferring data.<br>"
    512                 + "Details (untranslated): {1}</html>", e.getUrl(),
     512                + "Details (untranslated): {1}</html>",
     513                e != null ? e.getUrl() : "null",
    513514                ioe != null ? ioe.getMessage() : "null");
    514515    }
  • trunk/src/org/openstreetmap/josm/tools/Logging.java

    r11165 r11397  
    261261        StringWriter sb = new StringWriter();
    262262        sb.append(getErrorLog(message, t));
    263         sb.append('\n');
    264         t.printStackTrace(new PrintWriter(sb));
     263        if (t != null) {
     264            sb.append('\n');
     265            t.printStackTrace(new PrintWriter(sb));
     266        }
    265267        return sb.toString();
    266268    }
  • trunk/src/org/openstreetmap/josm/tools/Shortcut.java

    r11340 r11397  
    205205
    206206    public boolean isEvent(KeyEvent e) {
    207         return getKeyStroke() != null && getKeyStroke().equals(
    208         KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers()));
     207        KeyStroke ks = getKeyStroke();
     208        return ks != null && ks.equals(KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers()));
    209209    }
    210210
Note: See TracChangeset for help on using the changeset viewer.