From 31b408bbb39af390dc6fb09151b1649e43265bd4 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 18 May 2020 16:34:33 +0300 Subject: [PATCH] Fix possible npe --- .../java/net/osmand/router/RouteExporter.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteExporter.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteExporter.java index 02e571f4b5..2146bfe0f8 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteExporter.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteExporter.java @@ -11,6 +11,7 @@ import net.osmand.binary.RouteDataBundle; import net.osmand.binary.StringBundle; import net.osmand.binary.StringBundleWriter; import net.osmand.binary.StringBundleXmlWriter; +import net.osmand.util.Algorithms; import org.xmlpull.v1.XmlSerializer; @@ -38,20 +39,22 @@ public class RouteExporter { RouteDataResources resources = new RouteDataResources(locations); final RouteDataBundle bundle = new RouteDataBundle(resources); - for (RouteSegmentResult sr : route) { - sr.collectTypes(resources); - } - for (RouteSegmentResult sr : route) { - sr.collectNames(resources); - } + if (!Algorithms.isEmpty(route)) { + for (RouteSegmentResult sr : route) { + sr.collectTypes(resources); + } + for (RouteSegmentResult sr : route) { + sr.collectNames(resources); + } - List routeItems = new ArrayList<>(); - for (RouteSegmentResult sr : route) { - RouteDataBundle itemBundle = new RouteDataBundle(resources); - sr.writeToBundle(itemBundle); - routeItems.add(itemBundle); + List routeItems = new ArrayList<>(); + for (RouteSegmentResult sr : route) { + RouteDataBundle itemBundle = new RouteDataBundle(resources); + sr.writeToBundle(itemBundle); + routeItems.add(itemBundle); + } + bundle.putBundleList("route", "segment", routeItems); } - bundle.putBundleList("route", "segment", routeItems); List typeList = new ArrayList<>(); Map rules = resources.getRules();