Skip to content

Commit cc269ff

Browse files
author
boncey
committed
Better handle missing elements of Place data. Fix boncey#144
1 parent 4c00988 commit cc269ff

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

Flickr4Java/src/main/java/com/flickr4java/flickr/places/PlacesInterface.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -898,29 +898,27 @@ private Location parseLocation(Element locationElement) {
898898
location.setWoeName(locationElement.getAttribute("woe_name"));
899899
location.setIsHasShapeData("1".equals(locationElement.getAttribute("has_shapedata")));
900900
location.setPlaceType(stringPlaceTypeToInt(locationElement.getAttribute("place_type")));
901-
try {
902-
location.setLocality(parseLocationPlace(localityElement, Place.TYPE_LOCALITY));
903-
} catch (NullPointerException ex) {
904-
}
905-
try {
906-
location.setCounty(parseLocationPlace(countyElement, Place.TYPE_COUNTY));
907-
} catch (NullPointerException ex) {
908-
}
901+
location.setLocality(parseLocationPlace(localityElement, Place.TYPE_LOCALITY));
902+
location.setCounty(parseLocationPlace(countyElement, Place.TYPE_COUNTY));
909903
location.setRegion(parseLocationPlace(regionElement, Place.TYPE_REGION));
910904
location.setCountry(parseLocationPlace(countryElement, Place.TYPE_COUNTRY));
911905

912906
return location;
913907
}
914908

915909
private Place parseLocationPlace(Element element, int type) {
916-
Place place = new Place();
917-
place.setName(XMLUtilities.getValue(element));
918-
place.setPlaceId(element.getAttribute("place_id"));
919-
place.setPlaceUrl(element.getAttribute("place_url"));
920-
place.setWoeId(element.getAttribute("woeid"));
921-
place.setLatitude(element.getAttribute("latitude"));
922-
place.setLongitude(element.getAttribute("longitude"));
923-
place.setPlaceType(type);
910+
Place place = null;
911+
if (element != null) {
912+
place = new Place();
913+
place.setName(XMLUtilities.getValue(element));
914+
place.setPlaceId(element.getAttribute("place_id"));
915+
place.setPlaceUrl(element.getAttribute("place_url"));
916+
place.setWoeId(element.getAttribute("woeid"));
917+
place.setLatitude(element.getAttribute("latitude"));
918+
place.setLongitude(element.getAttribute("longitude"));
919+
place.setPlaceType(type);
920+
}
921+
924922
return place;
925923
}
926924

0 commit comments

Comments
 (0)