Ticket #14186: 14186.patch

File 14186.patch, 3.1 KB (added by GerdP, 7 years ago)
  • src/org/openstreetmap/josm/data/osm/DataSet.java

     
    977977        Set<Way> result = new HashSet<>();
    978978        beginUpdate();
    979979        try {
    980             for (Way way: ways) {
     980            List<Way> refWays = new ArrayList<>();
     981            for (OsmPrimitive ref : node.getReferrers()) {
     982                if (ref instanceof Way) {
     983                    refWays.add((Way) ref);
     984                }
     985            }
     986            for (Way way : refWays) {
    981987                List<Node> wayNodes = way.getNodes();
    982988                if (wayNodes.remove(node)) {
    983989                    if (wayNodes.size() < 2) {
  • test/unit/org/openstreetmap/josm/data/osm/DataSetTest.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.osm;
    33
     4import java.util.Arrays;
     5import java.util.List;
     6
     7import org.junit.Assert;
    48import org.junit.Rule;
    59import org.junit.Test;
    6 import org.junit.Assert;
     10import org.openstreetmap.josm.data.coor.LatLon;
    711import org.openstreetmap.josm.testutils.JOSMTestRules;
    812
    913import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    10 import java.util.List;
    11 import org.openstreetmap.josm.data.coor.LatLon;
    1214
    1315/**
    1416 * Unit tests for class {@link DataSet}.
     
    3335            "Empty data set should produce an empty list.",
    3436            ds.searchRelations(null).isEmpty()
    3537        );
    36        
     38
    3739        // empty data set, any bbox => empty list
    38         BBox bbox = new BBox(LatLon.NORTH_POLE, LatLon.SOUTH_POLE);
     40        BBox bbox = new BBox(new LatLon(-180, -90), new LatLon(180, 90));
    3941        Assert.assertTrue(
    4042            "Empty data set should produce an empty list.",
    4143            ds.searchRelations(bbox).isEmpty()
    4244        );
    43        
     45
    4446        // data set with elements in the given bbox => these elements
    4547        Node node = new Node(LatLon.ZERO);
    4648        Relation r = new Relation(1);
     
    5254        List<Relation> result = ds.searchRelations(bbox);
    5355        Assert.assertEquals("We should have found only one item.", 1, result.size());
    5456        Assert.assertTrue("The item found is relation r.", result.contains(r));
    55        
    5657    }
     58
     59    @Test
     60    public void testErr14186() {
     61        final DataSet ds = new DataSet();
     62        Node n1 = new Node(1);
     63        Node n2 = new Node(2);
     64        Node n3 = new Node(3);
     65        Way w1 = new Way(1);
     66        w1.setNodes(Arrays.asList(n1, n2, n3));
     67        Way w2 = new Way(2);
     68        w2.setNodes(Arrays.asList(n1, n2, n3));
     69        ds.addPrimitive(n1);
     70        ds.addPrimitive(n2);
     71        ds.addPrimitive(n3);
     72        ds.addPrimitive(w1);
     73        ds.addPrimitive(w2);
     74        ds.unlinkNodeFromWays(n2);
     75    }
     76
    5777}