westnordost / osmapi

Java client for the OSM API 0.6
GNU Lesser General Public License v3.0
97 stars 19 forks source link

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

Closed szbaalint closed 8 years ago

szbaalint commented 8 years ago

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
szbaalint commented 8 years ago

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

westnordost commented 8 years ago

pull request merged