Skip to content

Commit

Permalink
_itemsSource may be null in CarouselViewLoopManager (#11000)
Browse files Browse the repository at this point in the history
* _itemsSource may be null

I'm seeing a NullReferenceException in this method. There are no guards against `_itemsSource` being null, so dereferencing it to get its `Count` seems likely to be the problem.

* fix dropped semicolon

Co-authored-by: redth <jondick@gmail.com>
  • Loading branch information
BioTurboNick and Redth committed Nov 28, 2022
1 parent b6bbf79 commit 123fc7b
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public void CenterIfNeeded(RecyclerView recyclerView, bool isHorizontal)
{
if (!(recyclerView.GetLayoutManager() is LinearLayoutManager linearLayoutManager))
return;
if (_itemsSource is null)
return;

var itemSourceCount = _itemsSource.Count;

Expand Down Expand Up @@ -43,7 +45,9 @@ public int GetGoToIndex(RecyclerView recyclerView, int carouselPosition, int new
{
if (!(recyclerView.GetLayoutManager() is LinearLayoutManager linearLayoutManager))
return -1;

if (_itemsSource is null)
return -1;

var currentCarouselPosition = carouselPosition;
var itemSourceCount = _itemsSource.Count;

Expand Down

0 comments on commit 123fc7b

Please sign in to comment.