I have an error that unfortunately happens only in production for some users and I can't really reproduce in my development environment.
I have a feed in my app that contains texts, images, etc.
When trying to load an image using Glide sometimes it works but most of the time it fails and I get a blank image instead.
The images are ok as it works great on our iOS version and web interface.
I tried different DiskCacheStrategy and everything seems to fail, why am I getting a FileNotFound exception when I'm not even trying to load any file?
I tried running it both on Glide 4.6.1 and 4.7.1
Devices tested on: Huawei P10 Lite, Samsung A5 - running both on Android 7.0
GlideUrl glideUrl = new GlideUrl(urlToLoad, CustomHttpClient().getInstance().getGlideCookies());
GlideApp.with(mContext)
.load(glideUrl)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
Log.e(e);
loadingDone();
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
loadingDone();
return false;
}
private void loadingDone() {
imageView.setBackgroundResource(android.R.color.transparent);
progressBar.setVisibility(View.GONE);
}
})
.into(imageView);
This is the log I'm getting:
Non-fatal Exception: com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
java.io.FileNotFoundException(https://<SERVER_URL>/images/hd_1525270669285.jpg)
call GlideException#logRootCauses(String) for more detail
This is the full GlideException.logRootCauses() outpout:
Root cause (1 of 1)
java.io.FileNotFoundException: https://<SERVER_URL>/images/hd_1525260081532.png
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:250)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:106)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:59)
at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)
at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:299)
at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:269)
at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:776)
at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446)
Our server url, or any part of the url doesn't contain any special characters or untrimmed spaces.
Thanks!
Any help is highly appreciated !
The FileNotFoundException is actually thrown by OkHttp. It means that, for whatever reason, Android's networking library isn't able to load the urls you're requesting. Either the urls are invalid in some way or you've hit a bug in Android/OkHttp.
You can try an integration library to use a recent version of OkHttp, but otherwise there's not much we're likely to be able to do in Glide.
Hey,
Thanks for the answer.
I was finally to debug it, going through the OkHttp code helped me to figure it out.
Eventually it was a cookie and app-memory issue.
This issue can be marked as resolved.
Hey @slobglob
How exactly did you manage to resolve this
I can't seem to figure it out. My images load only on wifi but when use is on mobile data connection, the filenotfoundexception error prevents image from loading onto imageview.
@donUA
tbh, I can't recall exactly how it was fixed. I think it was related to some headers, if for you it happens only on cellular (but same endpoint) it might be permissions for android? Or do you explicitly set the network to use? If you can't get your head around this I would try to generate the same call with an http client running on android to see if it returns the image or any other relevant status code.
Hope I could help.
@sjudd saved my day!!!
@sjudd This is correct answer :D Thanks
Most helpful comment
The
FileNotFoundExceptionis actually thrown by OkHttp. It means that, for whatever reason, Android's networking library isn't able to load the urls you're requesting. Either the urls are invalid in some way or you've hit a bug in Android/OkHttp.You can try an integration library to use a recent version of OkHttp, but otherwise there's not much we're likely to be able to do in Glide.