Changeset 11166 in josm


Ignore:
Timestamp:
2016-10-26T13:09:07+02:00 (8 years ago)
Author:
simon04
Message:

fix #13827 - Exporting invalid multipolygon as GeoJSON crashes JOSM

Location:
trunk
Files:
2 edited

Legend:

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

    r10852 r11166  
    1818import javax.json.stream.JsonGenerator;
    1919
     20import org.openstreetmap.josm.Main;
    2021import org.openstreetmap.josm.data.Bounds;
    2122import org.openstreetmap.josm.data.coor.EastNorth;
     
    119120        @Override
    120121        public void visit(Relation r) {
    121             if (r != null && r.isMultipolygon() && !r.hasIncompleteMembers()) {
     122            if (r == null || !r.isMultipolygon() || r.hasIncompleteMembers()) {
     123                return;
     124            }
     125            try {
    122126                final Pair<List<JoinedPolygon>, List<JoinedPolygon>> mp = MultipolygonBuilder.joinWays(r);
    123127                final JsonArrayBuilder polygon = Json.createArrayBuilder();
     
    130134                final JsonArrayBuilder multiPolygon = Json.createArrayBuilder().add(polygon);
    131135                geomObj.add("coordinates", multiPolygon);
     136            } catch (MultipolygonBuilder.JoinedPolygonCreationException ex) {
     137                Main.warn("GeoJSON: Failed to export multipolygon " + r.getUniqueId());
     138                Main.warn(ex);
    132139            }
    133140        }
  • trunk/test/unit/org/openstreetmap/josm/io/GeoJSONWriterTest.java

    r10852 r11166  
    7777        }
    7878    }
     79
     80    /**
     81     * Unit test for exporting invalid multipolygons, see #13827
     82     * @throws Exception if an error occurs
     83     */
     84    @Test
     85    public void testMultipolygonRobustness() throws Exception {
     86        try (FileInputStream in = new FileInputStream("data_nodist/multipolygon.osm")) {
     87            DataSet ds = OsmReader.parseDataSet(in, null);
     88            final OsmDataLayer layer = new OsmDataLayer(ds, "foo", null);
     89            final GeoJSONWriter writer = new GeoJSONWriter(layer);
     90            assertTrue(writer.write().contains("MultiPolygon"));
     91        }
     92    }
    7993}
Note: See TracChangeset for help on using the changeset viewer.