Skip to content

Commit

Permalink
Merge pull request #10 from reciprocum/patch-9
Browse files Browse the repository at this point in the history
Would have NPE if presented with GPX file with zero waypoints, routes, or tracks.
  • Loading branch information
urizev authored Jul 2, 2021
2 parents 0d8e98b + b895c5a commit 489b0ed
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions src/com/urizev/gpx/GPXParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,33 +112,35 @@ public GPX parseGPX(InputStream in) throws Exception {
}
}
NodeList nodes = firstChild.getChildNodes();
for (int idx = 0; idx < nodes.getLength(); idx++) {
Node currentNode = nodes.item(idx);
if (GPXConstants.WPT_NODE.equals(currentNode.getNodeName())) {
Waypoint w = this.parseWaypoint(currentNode);
if (w != null) {
gpx.addWaypoint(w);
}
} else if (GPXConstants.TRK_NODE.equals(currentNode
.getNodeName())) {
Track trk = this.parseTrack(currentNode);
if (trk != null) {
gpx.addTrack(trk);
}
} else if (GPXConstants.EXTENSIONS_NODE.equals(currentNode
.getNodeName())) {
for (IExtensionParser parser : this.extensionParsers) {
Object data = parser.parseGPXExtension(currentNode);
gpx.addExtensionData(parser.getId(), data);
}
} else if (GPXConstants.RTE_NODE.equals(currentNode
.getNodeName())) {
Route rte = this.parseRoute(currentNode);
if (rte != null) {
gpx.addRoute(rte);

if (nodes != null)
for (int idx = 0; idx < nodes.getLength(); idx++) {
Node currentNode = nodes.item(idx);
if (GPXConstants.WPT_NODE.equals(currentNode.getNodeName())) {
Waypoint w = this.parseWaypoint(currentNode);
if (w != null) {
gpx.addWaypoint(w);
}
} else if (GPXConstants.TRK_NODE.equals(currentNode
.getNodeName())) {
Track trk = this.parseTrack(currentNode);
if (trk != null) {
gpx.addTrack(trk);
}
} else if (GPXConstants.EXTENSIONS_NODE.equals(currentNode
.getNodeName())) {
for (IExtensionParser parser : this.extensionParsers) {
Object data = parser.parseGPXExtension(currentNode);
gpx.addExtensionData(parser.getId(), data);
}
} else if (GPXConstants.RTE_NODE.equals(currentNode
.getNodeName())) {
Route rte = this.parseRoute(currentNode);
if (rte != null) {
gpx.addRoute(rte);
}
}
}
}
// TODO: parse route node
return gpx;
} else {
Expand Down

0 comments on commit 489b0ed

Please sign in to comment.