westnordost/osmapi

NullPointerException on nodes call when there are deleted nodes in the result

Closed this issue · 2 comments

The result of the nodes endpoint can contain deleted nodes. These nodes does not have lat and lon properties since they are invisible. In the case when there are at least one deleted node in the result, the parser throws a NullPointerException.

Here is an example response:
http://api.openstreetmap.org/api/0.6/nodes?nodes=5

<osm version="0.6" generator="CGImap 0.4.0 (6509 thorn-04.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
<node id="5" visible="false" version="4" changeset="9249514" timestamp="2011-09-08T21:13:24Z" user="mattfromderby" uid="15867"/>
</osm>

Here is the relevant part of the stacktrace:

Caused by: de.westnordost.osmapi.common.errors.XmlParserException: Error parsing XML at START_TAG (empty) @3:115 in java.io.InputStreamReader@28416773
    at de.westnordost.osmapi.common.XmlParser.doParse(XmlParser.java:59)
    at de.westnordost.osmapi.map.MapDataParser.parse(MapDataParser.java:62)
    at de.westnordost.osmapi.map.MapDataParser.parse(MapDataParser.java:25)
    at de.westnordost.osmapi.OsmConnection.handleResponse(OsmConnection.java:271)
    ... 36 more
Caused by: java.lang.NullPointerException
    at de.westnordost.osmapi.map.MapDataParser.onStartElement(MapDataParser.java:127)
    at de.westnordost.osmapi.common.XmlParser.doParse(XmlParser.java:40)
    ... 39 more

I've created a pull request with the fix: #3

pull request merged