Skip to content

Commit

Permalink
Merge pull request #26373 from brave/android_content_filters_crash
Browse files Browse the repository at this point in the history
Adds a null check on content filter list access on Android to prevent crash
  • Loading branch information
SergeyZhukovsky authored Nov 5, 2024
2 parents 4546d2a + 705130a commit 5d27097
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import java.util.Map;

public class ContentFilteringAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static int TYPE_FILTER_HEADER = 1;
private static int TYPE_CUSTOM_FILTER_LIST = 2;
private static int TYPE_FILTER_LIST = 3;
private static final int TYPE_FILTER_HEADER = 1;
private static final int TYPE_CUSTOM_FILTER_LIST = 2;
private static final int TYPE_FILTER_LIST = 3;

private static final int ONE_ITEM_SPACE = 1;
private static final int TWO_ITEMS_SPACE = 2;
Expand Down Expand Up @@ -254,9 +254,14 @@ public void setSubscriptionFilterLists(ArrayList<SubscriptionInfo> customFilterL

public void setFilterLists(Value filterLists[]) {
mFilterLists = filterLists;
notifyItemRangeInserted(
mSubscriptionFilterLists.size() + THREE_ITEMS_SPACE,
mFilterLists.length + ONE_ITEM_SPACE);
// mSubscriptionFilterLists could be null if setSubscriptionFilterLists
// hasn't been called yet. notifyItemRangeInserted is called inside
// setSubscriptionFilterLists, so we are good to skip it in that place
if (mSubscriptionFilterLists != null) {
notifyItemRangeInserted(
mSubscriptionFilterLists.size() + THREE_ITEMS_SPACE,
mFilterLists.length + ONE_ITEM_SPACE);
}
}

public static class FilterListHeaderViewHolder extends RecyclerView.ViewHolder {
Expand Down

0 comments on commit 5d27097

Please sign in to comment.