Skip to content

Commit

Permalink
'#1487 Better null pointer treatment for erroneous or incomplete
Browse files Browse the repository at this point in the history
nominatim responses that do not add certain nominatim fields.
  • Loading branch information
patrickdalla committed Sep 21, 2023
1 parent ebdcd51 commit d36fc22
Showing 1 changed file with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ public ArrayList<Country> getCountries() {

try {
SortedSetDocValues ssdv = reader.getSortedSetDocValues(NominatimTask.NOMINATIM_COUNTRY_METADATA);
TermsEnum te = ssdv.termsEnum();
BytesRef br = te.next();
while (br != null) {
countries.add(new Country(br.utf8ToString()));
br = te.next();
if (ssdv != null) {
TermsEnum te = ssdv.termsEnum();
BytesRef br = te.next();
while (br != null) {
countries.add(new Country(br.utf8ToString()));
br = te.next();
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
Expand All @@ -192,20 +194,22 @@ public State[] getStates(Country country) {

try {
SortedSetDocValues ssdv = reader.getSortedSetDocValues(NominatimTask.NOMINATIM_STATE_METADATA);
TermsEnum te = ssdv.termsEnum();
BytesRef br = te.next();
while (br != null) {
String stateCompleteName = br.utf8ToString();
if (stateCompleteName.startsWith(country.name)) {
found = true;
states.add(new State(country, stateCompleteName));
} else {
if (found) {
// it is not necessary to loop till the end as the data is sorted
break;
if (ssdv != null) {
TermsEnum te = ssdv.termsEnum();
BytesRef br = te.next();
while (br != null) {
String stateCompleteName = br.utf8ToString();
if (stateCompleteName.startsWith(country.name)) {
found = true;
states.add(new State(country, stateCompleteName));
} else {
if (found) {
// it is not necessary to loop till the end as the data is sorted
break;
}
}
br = te.next();
}
br = te.next();
}
} catch (IOException e) {
// TODO Auto-generated catch block
Expand Down Expand Up @@ -235,20 +239,22 @@ public City[] getCities(State state) {

try {
SortedSetDocValues ssdv = reader.getSortedSetDocValues(NominatimTask.NOMINATIM_CITY_METADATA);
TermsEnum te = ssdv.termsEnum();
BytesRef br = te.next();
while (br != null) {
String cityCompleteName = br.utf8ToString();
if (cityCompleteName.startsWith(state.name)) {
found = true;
cities.add(new City(state.country, state, cityCompleteName));
} else {
if (found) {
// it is not necessary to loop till the end as the data is sorted
break;
if (ssdv != null) {
TermsEnum te = ssdv.termsEnum();
BytesRef br = te.next();
while (br != null) {
String cityCompleteName = br.utf8ToString();
if (cityCompleteName.startsWith(state.name)) {
found = true;
cities.add(new City(state.country, state, cityCompleteName));
} else {
if (found) {
// it is not necessary to loop till the end as the data is sorted
break;
}
}
br = te.next();
}
br = te.next();
}
} catch (IOException e) {
// TODO Auto-generated catch block
Expand Down

0 comments on commit d36fc22

Please sign in to comment.