Changeset 17232 in josm


Ignore:
Timestamp:
2020-10-18T12:49:23+02:00 (7 days ago)
Author:
simon04
Message:

fix #19960 - NPE in OsmJsonReader.readRelationMembersAndTags

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmJsonReader.java

    r14219 r17232  
    157157    private void readRelationMembersAndTags(JsonObject item, Relation r, Collection<RelationMemberData> members)
    158158            throws IllegalDataException {
    159         for (JsonValue v : item.getJsonArray("members")) {
    160             JsonObject o = v.asJsonObject();
    161             members.add(parseRelationMember(r, ((JsonNumber) o.get("ref")).longValue(), o.getString("type"), o.getString("role")));
     159        JsonArray jsonArray = item.getJsonArray("members");
     160        if (jsonArray != null) {
     161            for (JsonValue v : jsonArray) {
     162                JsonObject o = v.asJsonObject();
     163                members.add(parseRelationMember(r, ((JsonNumber) o.get("ref")).longValue(), o.getString("type"), o.getString("role")));
     164            }
    162165        }
    163166        readTags(item, r);
  • trunk/test/unit/org/openstreetmap/josm/io/OsmJsonReaderTest.java

    r14219 r17232  
    236236        assertTrue(r.isTagged());
    237237        assertEquals("route", r.get("type"));
     238
     239    }
     240
     241    /**
     242     * Test a relation example without members.
     243     * @throws Exception never
     244     */
     245    @Test
     246    public void testEmptyRelation() throws Exception {
     247        DataSet ds = parse("{\n" +
     248                "  \"type\": \"relation\",\n" +
     249                "  \"id\": 1,\n" +
     250                "  \"tags\": {}\n" +
     251                "}");
     252        Relation r = ds.getRelations().iterator().next();
     253        assertEquals(1, r.getUniqueId());
     254        assertEquals(0, r.getMembersCount());
    238255    }
    239256
Note: See TracChangeset for help on using the changeset viewer.