Skip to content
This repository has been archived by the owner on Jan 14, 2018. It is now read-only.

Commit

Permalink
Merge pull request #140 from softwaremaverick/fix-concurrent-mod-exce…
Browse files Browse the repository at this point in the history
…ption

FIXED ConcurrentModificationException when adding a request listener to a request that's firing updates
  • Loading branch information
stephanenicolas committed Jul 11, 2013
2 parents 9d5a5f0 + b9ee52d commit 8a14278
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void addRequest(final CachedSpiceRequest<?> request, final Set<RequestLis
if (listRequestListenerForThisRequest == null) {
if (request.isProcessable()) {
Ln.d("Adding entry for type %s and cacheKey %s.", request.getResultType(), request.getRequestCacheKey());
listRequestListenerForThisRequest = new HashSet<RequestListener<?>>();
listRequestListenerForThisRequest = Collections.synchronizedSet(new HashSet<RequestListener<?>>());
this.mapRequestToRequestListener.put(request, listRequestListenerForThisRequest);
}
} else {
Expand Down Expand Up @@ -481,10 +481,12 @@ public void run() {
}

Ln.v("Notifying " + listeners.size() + " listeners of progress " + progress);
for (final RequestListener<?> listener : listeners) {
if (listener != null && listener instanceof RequestProgressListener) {
Ln.v("Notifying %s", listener.getClass().getSimpleName());
((RequestProgressListener) listener).onRequestProgressUpdate(progress);
synchronized (listeners) {
for (final RequestListener<?> listener : listeners) {
if (listener != null && listener instanceof RequestProgressListener) {
Ln.v("Notifying %s", listener.getClass().getSimpleName());
((RequestProgressListener) listener).onRequestProgressUpdate(progress);
}
}
}
}
Expand Down Expand Up @@ -514,15 +516,17 @@ public void run() {

final String resultMsg = spiceException == null ? "success" : "failure";
Ln.v("Notifying " + listeners.size() + " listeners of request " + resultMsg);
for (final RequestListener<?> listener : listeners) {
if (listener != null) {
@SuppressWarnings("unchecked")
final RequestListener<T> listenerOfT = (RequestListener<T>) listener;
Ln.v("Notifying %s", listener.getClass().getSimpleName());
if (spiceException == null) {
listenerOfT.onRequestSuccess(result);
} else {
listener.onRequestFailure(spiceException);
synchronized (listeners) {
for (final RequestListener<?> listener : listeners) {
if (listener != null) {
@SuppressWarnings("unchecked")
final RequestListener<T> listenerOfT = (RequestListener<T>) listener;
Ln.v("Notifying %s", listener.getClass().getSimpleName());
if (spiceException == null) {
listenerOfT.onRequestSuccess(result);
} else {
listener.onRequestFailure(spiceException);
}
}
}
}
Expand Down

0 comments on commit 8a14278

Please sign in to comment.