Can modify like this:
public RequestCreator load(String path) {
//if (path == null) {
// return new RequestCreator(this, null, 0);
//}
if (TextUtils.isEmpty(path)) {
return new RequestCreator(this, null, 0);
}
if (path.trim().length() == 0) {
throw new IllegalArgumentException("Path must not be empty.");
}
return load(Uri.parse(path));
}
An empty string is intentionally erroneous input. If you want to coerce an empty string to be equivalent to null
then you should do that in your application code before calling Picasso.
I ran into the same problem. It is not clear to me why null
and an empty string are handled differently. We handle this in the application code now, but I think it would be better to handle an empty sting like null
. It cannot imagine a situation where a runtime exception is better than ignoring the empty value and loading the placeholder.
If the behaviour should stay the same it would be great to communicate it by adding a throws
declaration to the methods.
Sorry to comment on an old issue but I ran into the same problem. I'm retrieving URL from an API, those URL are required according to my specs and so they will be unmarshalled into an empty string.
Some of the data doesn't have an URL and since this is an invalid URI, I fully expected Picasso to use the Resource defined with RequestCreator.Error() but instead it throws exceptions.
Giving a null string for the URI won't throw an exception but it will never timeout, it will use the placeholder resource and it will never swap to the error resource.
null isn't an error, so that is the behavior we expect, yes.
On Fri, Nov 3, 2017 at 7:58 AM Tristan notifications@github.com wrote:
Sorry to comment on an old issue but I ran into the same problem. I'm
retrieving URL from an API, those URL are required according to my specs
and so they will be unmarshalled into an empty string.Some of the data doesn't have an URL and since this is an invalid URI, I
fully expected Picasso to use the Resource defined with
RequestCreator.Error() but instead it throws exceptions.Giving a null string for the URI won't throw an exception but it will
never timeout, it will use the placeholder resource and it will never swap
to the error resource.—
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/1326#issuecomment-341727645,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEW32GMchPg6LZEs8yeva8GCtrZAXks5syyoNgaJpZM4H2tkI
.
Ok. How would I go about triggering an error to get the error image if I have an invalid URI?
In my use case I receive some URI from an API, the URI could be null, empty, malformed, or point to an dead link. All of those cases are erroneous. My placeholder is an animated spinner so when it tries to download from a valid URI we see that animation.
However, if given a bad URI I want to fallback to an error image.
In all cases but empty the error image will be shown because the URL could
not be fetched. If you want that behavior on empty, check for it yourself
and set the error image directly.
On Wed, Nov 8, 2017, 8:18 AM Tristan notifications@github.com wrote:
Ok. How would I go about triggering an error to get the error image if I
have an invalid URI?In my use case I receive some URI from an API, the URI could be null,
empty, malformed, or point to an dead link. All of those cases are
erroneous. My placeholder is an animated spinner so when it tries to
download from a valid URI we see that animation.However, if given a bad URI I want to fallback to an error image.
—
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/1326#issuecomment-342869069,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEZSWigKd7d-6zO3kIeiatCS15dBlks5s0dRXgaJpZM4H2tkI
.
Most helpful comment
I ran into the same problem. It is not clear to me why
null
and an empty string are handled differently. We handle this in the application code now, but I think it would be better to handle an empty sting likenull
. It cannot imagine a situation where a runtime exception is better than ignoring the empty value and loading the placeholder.If the behaviour should stay the same it would be great to communicate it by adding a
throws
declaration to the methods.