Skip to content

Commit 355c4f5

Browse files
ashishkumar468maskaravivek
authored andcommitted
Feature/nearby io fix (commons-app#1847)
* Bug fix issue commons-app#1839, changes * Extracted out PageTitle object's member varaible, displayText in a variable in findTemplate() in MediaDataExtractor * added null checks for the same varaible [Lets be safe side] * replaced equals with contains, ie. displayText.contains(title), so that uploads from multiple sources which have different formats still show up coordinates which was not being shown earlier * Bug fix issue commons-app#1846 1. Added null check in places in loadAttractionsFromLocation() in NearbyController 2. Catched exception in getFromWikidataQuery() which getFromWikidataQuery( )[Could be because of anything, primarily io]. * code formatting, adjusted whitespaces * return places which is initialised to empty list instead of null for places * replace catching Exception with the excact exception, ie. InterruptedIOException in NearbyPlaces
1 parent 4baabab commit 355c4f5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public NearbyPlacesInfo loadAttractionsFromLocation(LatLng curLatLng) throws IOE
5555
}
5656
List<Place> places = nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage());
5757

58-
if (places.size() > 0) {
58+
if (null != places && places.size() > 0) {
5959
LatLng[] boundaryCoordinates = {places.get(0).location, // south
6060
places.get(0).location, // north
6161
places.get(0).location, // west

app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.BufferedReader;
66
import java.io.IOException;
77
import java.io.InputStreamReader;
8+
import java.io.InterruptedIOException;
89
import java.net.URL;
910
import java.net.URLConnection;
1011
import java.util.ArrayList;
@@ -45,7 +46,12 @@ List<Place> getFromWikidataQuery(LatLng curLatLng, String lang) throws IOExcepti
4546

4647
// increase the radius gradually to find a satisfactory number of nearby places
4748
while (radius <= MAX_RADIUS) {
48-
places = getFromWikidataQuery(curLatLng, lang, radius);
49+
try {
50+
places = getFromWikidataQuery(curLatLng, lang, radius);
51+
} catch (InterruptedIOException e) {
52+
Timber.d("exception in fetching nearby places", e.getLocalizedMessage());
53+
return places;
54+
}
4955
Timber.d("%d results at radius: %f", places.size(), radius);
5056
if (places.size() >= MIN_RESULTS) {
5157
break;

0 commit comments

Comments
 (0)