Changeset 17375 in josm


Ignore:
Timestamp:
2020-11-29T10:57:33+01:00 (3 years ago)
Author:
GerdP
Message:

fix #20163: Split way corrupts relation when splitting via way

  • if via way in turn restriction is split we have to insert new member
Location:
trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/SplitWayCommand.java

    r17367 r17375  
    467467                        if (rValue.warnme) warnings.add(WarningType.GENERIC);
    468468                        insert = rValue.insert;
    469                         c = rValue.relation;
     469                        c = rValue.relation; // Value.relation is null or contains a modified copy
    470470                    } else if (!isOrderedRelation) {
    471471                        // Warn the user when relations that are not a route or multipolygon are modified as a result
     
    473473                        warnings.add(WarningType.GENERIC);
    474474                    }
    475                     if (c == null) {
    476                         c = new Relation(r);
    477                     }
    478475
    479476                    if (insert) {
     477                        if (c == null) {
     478                            c = new Relation(r);
     479                        }
    480480                        if (rm.hasRole() && !nowarnroles.contains(rm.getRole())) {
    481481                            warnings.add(WarningType.ROLE);
     
    818818                    c.addMember(new RelationMember(role, res));
    819819                    c.removeMembersFor(way);
    820                     relationInformation.insert = false;
    821820                }
    822             } else {
    823                 relationInformation.insert = false;
    824821            }
    825822        } else if (!"via".equals(role)) {
    826823            relationInformation.warnme = true;
     824        } else {
     825            relationInformation.insert = true;
    827826        }
    828827        relationInformation.relation = c;
  • trunk/test/unit/org/openstreetmap/josm/command/SplitWayCommandTest.java

    r17275 r17375  
    396396        }
    397397    }
     398
     399    /**
     400     * Non-regression test for issue #20163 (Split way corrupts relation when splitting via way)
     401     *
     402     * @throws IOException if any I/O error occurs
     403     * @throws IllegalDataException if OSM parsing fails
     404     */
     405    @Test
     406    void testTicket20163() throws IOException, IllegalDataException {
     407        try (InputStream is = TestUtils.getRegressionDataStream(20163, "data-20163.osm")) {
     408            DataSet ds = OsmReader.parseDataSet(is, null);
     409
     410            Way splitWay = (Way) ds.getPrimitiveById(757606841L, OsmPrimitiveType.WAY);
     411            Node splitNode = splitWay.getNode(1);
     412            Relation r = (Relation) ds.getPrimitiveById(10452821L, OsmPrimitiveType.RELATION);
     413            assertEquals(3, r.getMembersCount());
     414            assertFalse(r.getMembersFor(Collections.singleton(splitWay)).isEmpty());
     415            assertEquals(1, r.getMembers().stream().filter(rm -> "via".equals(rm.getRole())).count());
     416            assertEquals("via", r.getMembersFor(Collections.singleton(splitWay)).iterator().next().getRole());
     417            final Optional<SplitWayCommand> result = SplitWayCommand.splitWay(
     418                    splitWay,
     419                    SplitWayCommand.buildSplitChunks(splitWay, Collections.singletonList(splitNode)),
     420                    new ArrayList<>(),
     421                    Strategy.keepLongestChunk(),
     422                    // This split requires additional downloads but problem occured before the download
     423                    SplitWayCommand.WhenRelationOrderUncertain.SPLIT_ANYWAY
     424            );
     425
     426            // Should not result in aborting the split.
     427            assertTrue(result.isPresent());
     428            result.get().executeCommand();
     429
     430            assertTrue(r.isModified());
     431            assertEquals(4, r.getMembersCount());
     432            assertEquals(2, r.getMembers().stream().filter(rm -> "via".equals(rm.getRole())).count());
     433        }
     434    }
     435
    398436}
Note: See TracChangeset for help on using the changeset viewer.