turing-tech/MaterialScrollBar

INameableAdapter has undefined behaviour on empty list

dstd opened this issue · 1 comments

dstd commented

RecyclerView always calls the adapter with position within a data set bounds, so that when a data set is empty getItemViewType and onBindViewHolder won't be called.

According to the source code INameableAdapter could be called even if the list is empty, while the doc has nothing about this behaviour. Actually even the demo application is crashing if activity.getPackageManager().getInstalledApplications (AppData.java:AppData.processApps) returns an empty list, making testAdapter to try to reach a first element of empty list leading to OOB exception.

So I see two ways to solve this:

  1. make it clear that INameableAdapter.getCharacterForElement could be called with invalid index
  2. don't call this method when the list is empty

Thanks for the contribution.