WebCachedImageView icon indicating copy to clipboard operation
WebCachedImageView copied to clipboard

A bug in BitmapWorkerTask.cancelPotentialWork

Open FardadJalili opened this issue 12 years ago • 3 comments

I suppose Strings are not to be checked using == or != operator. Following code would be better: BitmapWorkerTask task = getBitmapWorkerTask(); if(task != null) { if(task.url != null) { if(task.url.equals(url)) return false; else task.cancel(true); } } return true;

FardadJalili avatar Aug 12 '13 10:08 FardadJalili

Hi, thanks for the contribution!

In that case, since Strings are final in Java, the == operator will work well, because it compares the reference and the url String object reference will be the same, since they'll point to the same immutable object.

The only case on which this would break is when the URL is generated dynamically, or when it is typed on an EditText (or something similar) by the user.

Since equals() is much slower than == and this code is very performance driven, I'm not sure that this would be a good addition. From my perspective, the majority of the cases where the developers show images in a list or from an URL in general, is because they got them from a JSON or XML from some kind of web service.

I think dynamically-generated URLs are not a common case, and the performance loss is not worth this fix. What do you think?

leocadiotine avatar Aug 13 '13 04:08 leocadiotine

The main problem with this code which is likely to happen is when someone using a code like this for example? BASE_URL = "http://example.com/photos.php?id=";

in Adapters getView for example: view.setImageUrl(BASE_URL+position);

In this case every call has a different reference (as far as I know about java that is, which is not a lot).

And you now how cursed asyncTasks are, even one of them will have an impact on the application.

Thank you for your sharing and managing this code

FardadJalili avatar Aug 13 '13 05:08 FardadJalili

You are absolutely right! This is the case on which the URLs are dynamically generated. I didn't think about the case on which the webservice returns only ids or handles.

I will submit this fix as soon as possible. Thanks a lot!

leocadiotine avatar Aug 13 '13 06:08 leocadiotine