From 61fe550b52adda8333dbbb069b406689ebd40eee Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 23 May 2020 10:47:05 +0200 Subject: [PATCH] Fix concurrent modification exception on start --- .../main/java/net/osmand/osm/MapPoiTypes.java | 40 ++++++++++++------- .../net/osmand/plus/poi/PoiFiltersHelper.java | 4 ++ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 4199abee89..60d835dbec 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -360,6 +360,11 @@ public class MapPoiTypes { final Map allTypes = new LinkedHashMap(); final Map> categoryPoiAdditionalMap = new LinkedHashMap>(); final Map> abstractTypeAdditionalCategories = new LinkedHashMap>(); + final Map poiTypesByTag = new LinkedHashMap(); + final Map deprecatedTags = new LinkedHashMap(); + final Map poiAdditionalCategoryIconNames = new LinkedHashMap(); + final List textPoiAdditionals = new ArrayList(); + List categoriesList = new ArrayList<>(); try { XmlPullParser parser = PlatformUtil.newXMLPullParser(); @@ -415,12 +420,15 @@ public class MapPoiTypes { if (lastCategory == null) { lastCategory = localOtherMapCategory; } - PoiType baseType = parsePoiAdditional(parser, lastCategory, lastFilter, lastType, null, null, lastPoiAdditionalCategory); + PoiType baseType = parsePoiAdditional(parser, lastCategory, lastFilter, lastType, null, null, + lastPoiAdditionalCategory, textPoiAdditionals); if ("true".equals(parser.getAttributeValue("", "lang"))) { for (String lng : MapRenderingTypes.langs) { - parsePoiAdditional(parser, lastCategory, lastFilter, lastType, lng, baseType, lastPoiAdditionalCategory); + parsePoiAdditional(parser, lastCategory, lastFilter, lastType, lng, baseType, + lastPoiAdditionalCategory, textPoiAdditionals); } - parsePoiAdditional(parser, lastCategory, lastFilter, lastType, "en", baseType, lastPoiAdditionalCategory); + parsePoiAdditional(parser, lastCategory, lastFilter, lastType, "en", baseType, + lastPoiAdditionalCategory, textPoiAdditionals); } if (lastPoiAdditionalCategory != null) { List categoryAdditionals = categoryPoiAdditionalMap.get(lastPoiAdditionalCategory); @@ -491,7 +499,7 @@ public class MapPoiTypes { } } } - categories = categoriesList; + is.close(); } catch (IOException e) { log.error("Unexpected error", e); //$NON-NLS-1$ @@ -519,17 +527,25 @@ public class MapPoiTypes { List poiAdditionals = categoryPoiAdditionalMap.get(category); if (poiAdditionals != null) { for (PoiType poiType : poiAdditionals) { - buildPoiAdditionalReference(poiType, entry.getKey()); + buildPoiAdditionalReference(poiType, entry.getKey(), textPoiAdditionals); } } } } - findDefaultOtherCategory(); + this.categories = categoriesList; + this.poiTypesByTag = poiTypesByTag; + this.deprecatedTags = deprecatedTags; + this.poiAdditionalCategoryIconNames = poiAdditionalCategoryIconNames; + this.textPoiAdditionals = textPoiAdditionals; + otherCategory = getPoiCategoryByName("user_defined_other"); + if (otherCategory == null) { + throw new IllegalArgumentException("No poi category other"); + } init = true; log.info("Time to init poi types " + (System.currentTimeMillis() - time)); //$NON-NLS-1$ } - private PoiType buildPoiAdditionalReference(PoiType poiAdditional, AbstractPoiType parent) { + private PoiType buildPoiAdditionalReference(PoiType poiAdditional, AbstractPoiType parent, List textPoiAdditionals) { PoiCategory lastCategory = null; PoiFilter lastFilter = null; PoiType lastType = null; @@ -580,7 +596,8 @@ public class MapPoiTypes { } private PoiType parsePoiAdditional(XmlPullParser parser, PoiCategory lastCategory, PoiFilter lastFilter, - PoiType lastType, String lang, PoiType langBaseType, String poiAdditionalCategory) { + PoiType lastType, String lang, PoiType langBaseType, + String poiAdditionalCategory, List textPoiAdditionals) { String oname = parser.getAttributeValue("", "name"); if (lang != null) { oname += ":" + lang; @@ -662,13 +679,6 @@ public class MapPoiTypes { return tp; } - private void findDefaultOtherCategory() { - PoiCategory pc = getPoiCategoryByName("user_defined_other"); - if (pc == null) { - throw new IllegalArgumentException("No poi category other"); - } - otherCategory = pc; - } public List getCategories(boolean includeMapCategory) { ArrayList lst = new ArrayList(categories); diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java index 0037c5634b..d24109f6f2 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java @@ -617,6 +617,10 @@ public class PoiFiltersHelper { } public void loadSelectedPoiFilters() { + // don't deal with not loaded poi types + if(!application.getPoiTypes().isInit()) { + return; + } selectedPoiFilters.clear(); OsmandSettings settings = application.getSettings(); Set filters = settings.getSelectedPoiFilters();