Ticket #24368: 24368.patch

File 24368.patch, 3.0 KB (added by GerdP, 11 months ago)

catch exception, unit test

  • src/org/openstreetmap/josm/data/validation/tests/ConnectivityRelations.java

     
    169169                break;
    170170            }
    171171        }
     172
    172173        // Lane count from member tags
    173174        for (RelationMember rM : relation.getMembers()) {
    174175            // Check lanes
     
    179180                    List<Long> laneCounts = new ArrayList<>();
    180181                    long maxLaneCount;
    181182                    if (prim.hasTag("lanes")) {
    182                         laneCounts.add(Long.parseLong(prim.get("lanes")));
     183                        try {
     184                            laneCounts.add(Long.parseLong(prim.get("lanes")));
     185                        } catch (NumberFormatException e) {
     186                            return Collections.emptyMap();
     187                        }
    183188                    }
    184189                    for (Entry<String, String> entry : primKeys.entrySet()) {
    185190                        String thisKey = entry.getKey();
  • test/unit/org/openstreetmap/josm/data/validation/tests/ConnectivityRelationsTest.java

     
    22package org.openstreetmap.josm.data.validation.tests;
    33
    44import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertTrue;
    56
    67import org.junit.jupiter.api.BeforeEach;
    78import org.junit.jupiter.api.Test;
     
    89import org.openstreetmap.josm.TestUtils;
    910import org.openstreetmap.josm.data.coor.LatLon;
    1011import org.openstreetmap.josm.data.osm.Node;
     12import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1113import org.openstreetmap.josm.data.osm.Relation;
    1214import org.openstreetmap.josm.data.osm.RelationMember;
    1315
     
    99101        check.visit(relation);
    100102        assertEquals(++expectedFailures, check.getErrors().size());
    101103    }
     104
     105    /**
     106     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/201821">Bug #20182</a>.
     107     */
     108    @Test
     109    void testTicket24368() {
     110        Relation relation = createDefaultTestRelation();
     111        check.visit(relation);
     112
     113        assertEquals(0, check.getErrors().size());
     114
     115        // change lanes for one way to an invalid value as reported in the ticket
     116        boolean changed = false;
     117        for (OsmPrimitive m : relation.getChildren()) {
     118            if ("4".equals(m.get("lanes"))) {
     119                m.put("lanes", "25 mph");
     120                changed = true;
     121                break;
     122            }
     123        }
     124        assertTrue(changed);
     125        check.visit(relation);
     126        assertEquals(0, check.getErrors().size());
     127
     128    }
    102129}