turing-tech / MaterialScrollBar

An Android library that brings the Material Design 5.1 sidebar to pre-5.1 devices.
Apache License 2.0
781 stars 126 forks source link

INameableAdapter has undefined behaviour on empty list #87

Closed dstd closed 7 years ago

dstd commented 7 years ago

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
turing-tech commented 7 years ago

Thanks for the contribution.