From 41be54750fdc1b37ea69dc3cd417b4db55294cc7 Mon Sep 17 00:00:00 2001 From: Pavol Zibrita Date: Tue, 17 Jul 2012 02:00:44 +0200 Subject: [PATCH] fixed java.lang.IndexOutOfBoundsException when first way was without any nodes. --- .../net/osmand/data/MultipolygonTest.java | 9 ++++++- .../src/net/osmand/data/Multipolygon.java | 26 ++++++++++--------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/DataExtractionOSM/src-tests/net/osmand/data/MultipolygonTest.java b/DataExtractionOSM/src-tests/net/osmand/data/MultipolygonTest.java index 7e57693303..ac94ae6cc2 100644 --- a/DataExtractionOSM/src-tests/net/osmand/data/MultipolygonTest.java +++ b/DataExtractionOSM/src-tests/net/osmand/data/MultipolygonTest.java @@ -168,6 +168,13 @@ public class MultipolygonTest { assertFalse(testee.hasOpenedPolygons()); } - + @Test + public void test_firstEmptyWayThanOpenedWay() + { + testee.addOuterWay(new Way(111)); + testee.addOuterWay(poly1_1_of_2); + assertEquals(1, testee.countOuterPolygons()); + assertTrue(testee.hasOpenedPolygons()); + } } diff --git a/DataExtractionOSM/src/net/osmand/data/Multipolygon.java b/DataExtractionOSM/src/net/osmand/data/Multipolygon.java index 47bd17601c..48bd769697 100644 --- a/DataExtractionOSM/src/net/osmand/data/Multipolygon.java +++ b/DataExtractionOSM/src/net/osmand/data/Multipolygon.java @@ -32,18 +32,20 @@ public class Multipolygon { protected IdentityHashMap> outerInnerMapping; private void addNewPolygonPart(List polygons, List closedPolygons, Way newPoly) { - if (isClosed(newPoly)) { - closedPolygons.add(newPoly); //if closed, put directly to closed polygons - } else if (polygons.isEmpty()) { - polygons.add(newPoly); //if open, and first, put to polygons.. - } else { - // now we try to merge the ways to form bigger polygons - Stack wayStack = new Stack(); - wayStack.push(newPoly); - addAndMergePolygon(polygons, closedPolygons, wayStack); - } - //reset the mapping - outerInnerMapping = null; + if (!newPoly.getNodes().isEmpty()) { + if (isClosed(newPoly)) { + closedPolygons.add(newPoly); //if closed, put directly to closed polygons + } else if (polygons.isEmpty()) { + polygons.add(newPoly); //if open, and first, put to polygons.. + } else { + // now we try to merge the ways to form bigger polygons + Stack wayStack = new Stack(); + wayStack.push(newPoly); + addAndMergePolygon(polygons, closedPolygons, wayStack); + } + //reset the mapping + outerInnerMapping = null; + } //else do nothing } private boolean isClosed(Way newPoly) {