Skip to content

Glide.with throws unnecessary and undocumented exception #5528

@nikclayton

Description

@nikclayton

In Glide 4.16.0 I'm trying to cancel a load in response to a callback from a third party library.

The third party library is tracking the view lifecycle, and when the view is detached calls my callback to cancel any outstanding image loads. The view might be detached as part of the normal view lifecycle when it's a view managed by an adapter associated with a RecyclerView and the user is scrolling, or it might be detached because the activity is ending.

The function (i.e., my code) it's calling looks like this:

    override fun cancel(imageView: ImageView) {
        Glide.with(imageView).clear(imageView)
    }

That throws an undocumented IllegalArgumentException because Glide.with eventually calls this in RequestManagerRetriever.java:

  @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
  private static void assertNotDestroyed(@NonNull Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && activity.isDestroyed()) {
      throw new IllegalArgumentException("You cannot start a load for a destroyed activity");
    }
  }

This is misleading, as I am not trying to "start a load for a destroyed activity". At worst, calling .clear(imageView) when the activity is destroyed should be a no-op.

Please document this exception. Please also consider pushing this assert to the .load() methods, and/or only asserting in debug builds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions