Skip to content

Commit

Permalink
Avoid concurrent modifications when notifying ViewTarget callbacks.
Browse files Browse the repository at this point in the history
Fixes #2237.
  • Loading branch information
sjudd committed Aug 15, 2017
1 parent 81b179b commit cac7192
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ private static class SizeDeterminer {
}

private void notifyCbs(int width, int height) {
for (SizeReadyCallback cb : cbs) {
// One or more callbacks may trigger the removal of one or more additional callbacks, so we
// need a copy of the list to avoid a concurrent modification exception. One place this
// happens is when a full request completes from the in memory cache while its thumbnail is
// still being loaded asynchronously. See #2237.
for (SizeReadyCallback cb : new ArrayList<>(cbs)) {
cb.onSizeReady(width, height);
}
}
Expand Down Expand Up @@ -218,6 +222,12 @@ void getSize(SizeReadyCallback cb) {
}
}

/**
* The callback may be called anyway if it is removed by another {@link SizeReadyCallback} or
* otherwise removed while we're notifying the list of callbacks.
*
* <p>See #2237.
*/
void removeCallback(SizeReadyCallback cb) {
cbs.remove(cb);
}
Expand Down

0 comments on commit cac7192

Please sign in to comment.