LocationPickerActivity.java: add null checks to showInMapApp

Before this change, there was no null checks when accessing data from an object,
which could create null pointer exceptions at runtime.

After this change, null checks are introduced to make sure null pointer exceptions will not occur.
This commit is contained in:
Jason Whitmore 2024-07-06 16:17:24 -07:00
parent efe6eb27ed
commit caed893d23

View file

@ -400,18 +400,20 @@ public class LocationPickerActivity extends BaseActivity implements
* If there is no EXIF data, the map will center on the commons app map center. * If there is no EXIF data, the map will center on the commons app map center.
*/ */
private void showInMapApp() { private void showInMapApp() {
fr.free.nrw.commons.location.LatLng position = null; fr.free.nrw.commons.location.LatLng position = null;
//Check to see if EXIF location data is available //Check to see if EXIF location data is available
if(activity.equals("UploadActivity")){ if(activity.equals("UploadActivity") && cameraPosition != null){
position = new fr.free.nrw.commons.location.LatLng(cameraPosition.getLatitude(), position = new fr.free.nrw.commons.location.LatLng(cameraPosition.getLatitude(),
cameraPosition.getLongitude(), 0.0f); cameraPosition.getLongitude(), 0.0f);
} else { } else if(mapView != null){
position = new fr.free.nrw.commons.location.LatLng(mapView.getMapCenter().getLatitude(), position = new fr.free.nrw.commons.location.LatLng(mapView.getMapCenter().getLatitude(),
mapView.getMapCenter().getLongitude(), 0.0f); mapView.getMapCenter().getLongitude(), 0.0f);
} }
Utils.handleGeoCoordinates(this, position); if(position != null){
Utils.handleGeoCoordinates(this, position);
}
} }
/** /**