It wired to observe that Picasso has not handled null and Empty url
1) If null is passed in Picasso.load() it never loads error Image which is required
2) If blank image passed in Picasso.load() app gets crashed gives Path must not be empty Exception happens
Developer need to add validation for both the cases.
Thanks in advance
Looking forward your reply
Passing null
is not an error, so Picasso will either clear the ImageView
or load your placeholder if you specify one. This is a required and expected behaviour for view recycling.
An empty path is not valid, so Picasso throws an exception. What validation do you want here?
Please, just make your code better. Why are you passing an empty url?????
Urls are received from webservices , So if for certain webservice , image url is not there , it might return null or nothing. I think for these cases it should give error Image instead of throwing exception.
You can filter empty URLs to null before passing them to Picasso.
On Mar 9, 2015 5:23 AM, "neodroidpune" [email protected] wrote:
Urls are received from webservices , So if for certain webservice , image
url is not there , it might return null or nothing. I think for these cases
it should give error Image instead of throwing exception.—
Reply to this email directly or view it on GitHub
https://github.com/square/picasso/issues/899#issuecomment-77821799.
ya sure I can I just curious that why Picasso doesnt have such validation ,
Thanks for support.
Because while null is a very explicit thing, an empty URL has no meaning
and is always almost a sign of an error or bad data.
On Mar 9, 2015 9:30 AM, "neodroidpune" [email protected] wrote:
ya sure I can I just curious that why Picasso doesnt have such validation ,
Thanks for support.—
Reply to this email directly or view it on GitHub
https://github.com/square/picasso/issues/899#issuecomment-77852895.
Whatever is the bad value, be it null or null String, it would be much better to load the ImageView with the provided place holder image or just clear the ImageView if no Place Holder is provided by the user. This would be a better Fall back for the Image Loading Right? Can you please include such behaviour.
No. See my previous comments as to why.
On Wed, Mar 23, 2016, 6:32 AM SriKrishnaCovalense [email protected]
wrote:
Whatever is the bad value, be it null or null String, it would be much
better to load the ImageView with the provided place holder image or just
clear the ImageView if no Place Holder is provided by the user. This would
be a better Fall back for the Image Loading Right? Can you please include
such behaviour.—
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub
https://github.com/square/picasso/issues/899#issuecomment-200287394
Hi,
Is there a particular reason to raised IllegalArgumentException as it's unchecked ? Some webservices returns empty strings so imho it would be preferable to warn the user of the API
Thanks
Picasso's behaviour is not wrong but we are not living perfect world. I don't want to check every time and I can't change server side codes. If you add a global setting for this, it can be very useful. like this
Picasso.showErrorIfNullOrEmpty(true);
I'm agree with you, I did not knew this global settings, this is what I was looking for. Thanks
I would understand crashing like this if there were any kind of uri validation, but right now I could pass a string like "!@#$%ˆ*()+_~"
to Picasso without a crash. So why should an empty string crash it?
I would also suggest giving the developers an option to specify the default behaviour in case of invalid uri.
Because it's the absence of data where you indicated there was data. And
no, we won't be providing an option for behavior.
On Mon, Aug 22, 2016 at 11:34 AM Luca Vitucci [email protected]
wrote:
I would understand crashing like this if there were any kind of uri
validation, but right now I could pass a string like "!@#$%ˆ*()+_~" to
Picasso without a crash. So why should an empty string crash it?
I would also suggest giving the developers an option to specify the
default behaviour in case of invalid uri.—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/square/picasso/issues/899#issuecomment-241452408, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAEEEQ1-_VSY8iE-SGx_AxxCv5Q99T3eks5qicF1gaJpZM4Disgs
.
Let's assume that we fetch our images from remote API, and the image can not be present for a particular user. Instead, we want to show some placeholder (we can't use .placeholder because it makes a loading indicator for us to show that we are fetching something). For now, we need to make null check like this:
if (photoPath == null)
Picasso.with(this)
.load(photoPath != null ? photoPath : R.drawable.avatar_placeholder)
.placeholder(new MaterialProgressDrawable(this))
.transform(new CircleTransformation())
.into(userPhotoImageView);
else
Picasso.with(this)
.load(photoPath)
.placeholder(new MaterialProgressDrawable(this))
.transform(new CircleTransformation())
.into(userPhotoImageView);
Really there is no better way ? It's ok for one-time action but makes a lot of boilerplate code when used across the whole project.
Not only for null path. If is empty or invalid url like "/" it crash
I see some people don't understand the difference between "String == null" and "" (or "String.isEmpty()" in later case). If "path == null", then it is a valid case to display placeholder or error image. In case if "path != null", but it is empty ("" or String.isEmtry()) than this is a response from server and should be handled by developer. @lukasz-gosiewski got completely wrong logic to handle this cases
I'm so glad Picasso looks like Glide, makes migrating to it a whole lot easier. I can finally say goodbye to isEmpty()
. It feels like Glide at least respects us
Propagating invalid data isn't respect, it's negligence. You should normalize at your API boundaries instead of propagating it to your view layer as well so you're both at fault.
I'm fine with being _'at fault'_ here, it's not like it matters since I proudly migrated to Glide anyway
We don't care. Open source libraries aren't a religion.
You can use this code for image loading in picasso.
if (TextUtils.isEmpty(item.getImgPath())) {
Picasso.with(context).cancelRequest(imgProduct);
imgProduct.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.img_back_splash));
} else {
Picasso.with(context)
.load(item.getImgPath())
.noFade()
.into(imgProduct);
}
Most helpful comment
I would understand crashing like this if there were any kind of uri validation, but right now I could pass a string like
"!@#$%ˆ*()+_~"
to Picasso without a crash. So why should an empty string crash it?I would also suggest giving the developers an option to specify the default behaviour in case of invalid uri.