nearby: make sure places is initialized (#5241)

On taking a look at the following stack trace:

  java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference
  at fr.free.nrw.commons.nearby.fragments.NearbyParentFragment.updatePlaceList(NearbyParentFragment.java:777)
  at fr.free.nrw.commons.nearby.fragments.NearbyParentFragment.lambda$initFilterChips$10$NearbyParentFragment(NearbyParentFragment.java:730)
  at fr.free.nrw.commons.nearby.fragments.-$$Lambda$NearbyParentFragment$AGol6SoJlvIYd45Vbz6tTjDiWU4.onCheckedChanged(Unknown Source:2)
  at android.widget.CompoundButton.setChecked(CompoundButton.java:235)
  at com.google.android.material.chip.Chip.setChecked(Chip.java:665)
  at android.widget.CompoundButton.toggle(CompoundButton.java:150)
  ...

... it seems clear the 'places' list is trying to be iterated
in the updatePlaceList method when it is empty. This is resulting
in an NPE and consequently an app crash.

Avoid the same by ensuring it is always initialized to an empty list.
This commit is contained in:
Kaartic Sivaraam 2023-06-19 16:53:20 +05:30 committed by GitHub
parent 00b69c6731
commit f4e8de79fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -259,7 +259,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
/**
* Saves response of list of places for the first time
*/
private List<Place> places;
private List<Place> places = new ArrayList<>();
@NonNull
public static NearbyParentFragment newInstance() {