Changeset 15354 in josm for trunk


Ignore:
Timestamp:
2019-09-17T09:15:17+02:00 (5 years ago)
Author:
GerdP
Message:

fix #18137: NPE in UnconnectedWays

Location:
trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java

    r15344 r15354  
    5353
    5454    protected abstract boolean isCandidate(OsmPrimitive p);
     55
     56    protected boolean isWantedWay(Way w) {
     57        return w.isUsable() && isCandidate(w);
     58    }
    5559
    5660    /**
     
    320324    private Way getWantedParentWay(Node endnode) {
    321325        for (Way w : endnode.getParentWays()) {
    322             if (isCandidate(w))
     326            if (isWantedWay(w))
    323327                return w;
    324328        }
     
    360364
    361365        for (Way w : ds.getWays()) {
    362             if (w.isUsable() && isCandidate(w) && w.getRealNodesCount() > 1) {
     366            if (isWantedWay(w) && w.getRealNodesCount() > 1) {
    363367                waySegments.addAll(getWaySegments(w));
    364368                addNode(w.firstNode(), endnodes);
     
    445449                visited.add(node);
    446450                for (final Way way : node.getParentWays()) {
    447                     if (isCandidate(way)) {
     451                    if (isWantedWay(way)) {
    448452                        List<Node> nextNodes = new ArrayList<>();
    449453                        int pos = way.getNodes().indexOf(node);
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/UnconnectedWaysTest.java

    r15335 r15354  
    22package org.openstreetmap.josm.data.validation.tests;
    33
     4import static org.CustomMatchers.hasSize;
    45import static org.CustomMatchers.isEmpty;
    56import static org.junit.Assert.assertThat;
     
    6061
    6162    /**
    62      * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/6313">Bug #18051</a>.
     63     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/18051">Bug #18051</a>.
    6364     * @throws IOException if any I/O error occurs
    6465     * @throws IllegalDataException if the OSM data cannot be parsed
     
    8081
    8182    /**
    82      * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/6313">Bug #18106</a>.
     83     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/18136">Bug #18106</a>.
    8384     * @throws IOException if any I/O error occurs
    8485     * @throws IllegalDataException if the OSM data cannot be parsed
     
    9899        }
    99100    }
     101
     102    /**
     103     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/18137">Bug #18137</a>.
     104     * @throws IOException if any I/O error occurs
     105     * @throws IllegalDataException if the OSM data cannot be parsed
     106     * @throws FileNotFoundException if the data file cannot be found
     107     */
     108    @Test
     109    public void testTicket18137() throws IOException, IllegalDataException, FileNotFoundException {
     110        try (InputStream fis = TestUtils.getRegressionDataStream(18137, "18137_npe.osm")) {
     111            final DataSet ds = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     112            MainApplication.getLayerManager().addLayer(new OsmDataLayer(ds, null, null));
     113
     114            bib.startTest(null);
     115            bib.setBeforeUpload(true);
     116            bib.visit(ds.allPrimitives());
     117            bib.endTest();
     118            assertThat(bib.getErrors(), hasSize(2));
     119        }
     120    }
    100121}
Note: See TracChangeset for help on using the changeset viewer.