Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make parameter payloads @Nullable in onBindViewHolder method in AdapterDelegate and AbsListItemAdapterDelegate classes. #30

Closed
netimen opened this issue Jan 4, 2017 · 4 comments

Comments

@netimen
Copy link

netimen commented Jan 4, 2017

there is a method protected abstract void onBindViewHolder(@NonNull T items, int position, @NonNull RecyclerView.ViewHolder holder, @NonNull List<Object> payloads); in AdapterDelegate class. But the actual value of payloads parameter is null quite often, here is an example callstack f(I'm using AbsListItemAdapterDelegate here):

at com.hannesdorfmann.adapterdelegates3.AbsListItemAdapterDelegate.onBindViewHolder(AbsListItemAdapterDelegate.java:50)
at com.hannesdorfmann.adapterdelegates3.AbsListItemAdapterDelegate.onBindViewHolder(AbsListItemAdapterDelegate.java:41)
at com.hannesdorfmann.adapterdelegates3.AdapterDelegatesManager.onBindViewHolder(AdapterDelegatesManager.java:281)
at com.hannesdorfmann.adapterdelegates3.AbsDelegationAdapter.onBindViewHolder(AbsDelegationAdapter.java:78)

the problem is very severe with Kotlin: when I override this method I have to use non-null syntax for payloads: override fun onBindViewHolder(item: T, viewHolder: RecyclerView.ViewHolder, payloads: MutableList<Any>) so I get java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter payloads at runtime

Currently I have to use a pretty ugly workaround but it's very frustrating

@netimen netimen changed the title please make parameter payloads @Nullable in onBindViewHolder method in AdapterDelegate and AbsListItemAdapterDelegate classes. Make parameter payloads @Nullable in onBindViewHolder method in AdapterDelegate and AbsListItemAdapterDelegate classes. Jan 4, 2017
@netimen
Copy link
Author

netimen commented Jan 4, 2017

Actually there is a little bit strange code in AbsListItemAdapterDelegate:

@Override protected final void onBindViewHolder(@NonNull List<T> items, int position,
      @NonNull RecyclerView.ViewHolder holder, @Nullable List<Object> payloads) {
    onBindViewHolder((I) items.get(position), (VH) holder, payloads);
  }

here payloads have @Nullable, but payloads in super class method have @NonNull and the payloads in the overloaded method called from here also have @NonNull :)

@sockeqwe
Copy link
Owner

sockeqwe commented Jan 4, 2017

Thanks for reporting!
Indeed, I made a mess with @NonNull / @Nullable annotations.
Actually payload should never be null hence @NonNull is the correct annotation and should be used everywhere.

However, I'm not sure where the real issue comes from. This libary internally always uses a empty list and not null. So I assume that RecyclerView itself is passing null as payload to your adapter although the javadoc of recyclerview say that:

A non-null list of merged payloads. Can be empty list if requires full update.

I'm not sure whether or not this is a bug in RecyclerView library or a documentation issue or a DiffUtils issue.

I have added a check that ensure that always an empty list instead of null will be passed to the AdapterDelegate.onBindViewHolder(...) method so that the @NonNull annotation is correct.

I have published a SNAPSHOT containing this fix. Please verify that the latest snapshot 3.0.1-SNAPSHOT fixes your crash.

@netimen
Copy link
Author

netimen commented Jan 7, 2017

Thanks! seems to work now

@sockeqwe
Copy link
Owner

sockeqwe commented Jan 7, 2017

I just have released in 3.0.1 containing this fix.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants