bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.67k stars 6.12k forks source link

downloadOnly + DiskCacheStrategy.NONE throws exception #4626

Open NWuensche opened 3 years ago

NWuensche commented 3 years ago

Glide Version: 4.12.0

Integration libraries: No

Device/Android Version: Emulator and Samsung Galaxy S20

Issue details / Repro steps / Use case background: Running the following code (Using RxJava2 for Networking, but error also was there with coroutines):

        Single.fromCallable {
            val f = Glide.with(applicationContext)
                .downloadOnly()
                .load("https://upload.wikimedia.org/wikipedia/commons/b/b6/Image_created_with_a_mobile_phone.png")
                .submit()
                .get()
        }.subscribeOn(Schedulers.io()).subscribe()

runs with no problem. However, adding DiskCacheStrategy.NONE like so:

        Single.fromCallable {
            val f = Glide.with(applicationContext)
                .downloadOnly()
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .load("https://upload.wikimedia.org/wikipedia/commons/b/b6/Image_created_with_a_mobile_phone.png")
                .submit()
                .get()
        }.subscribeOn(Schedulers.io()).subscribe()

fails with the following java.util.concurrent.ExecutionException :

E/AndroidRuntime: FATAL EXCEPTION: RxCachedThreadScheduler-1
    Process: de.nwuensche.myapplication, PID: 10684
    io.reactivex.exceptions.OnErrorNotImplementedException: The exception was not handled due to missing onError handler in the subscribe() method call. Further reading: https://github.com/ReactiveX/RxJava/wiki/Error-Handling | java.util.concurrent.ExecutionException: com.bumptech.glide.load.engine.GlideException: Failed to load resource
        at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
        at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)
        at io.reactivex.internal.observers.ConsumerSingleObserver.onError(ConsumerSingleObserver.java:46)
        at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.onError(SingleSubscribeOn.java:73)
        at io.reactivex.internal.operators.single.SingleFromCallable.subscribeActual(SingleFromCallable.java:48)
        at io.reactivex.Single.subscribe(Single.java:3603)
        at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
        at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578)
        at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
        at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
     Caused by: java.util.concurrent.ExecutionException: com.bumptech.glide.load.engine.GlideException: Failed to load resource
        at com.bumptech.glide.request.RequestFutureTarget.doGet(RequestFutureTarget.java:217)
        at com.bumptech.glide.request.RequestFutureTarget.get(RequestFutureTarget.java:130)
        at de.nwuensche.myapplication.MainActivity.onCreate$lambda-1(MainActivity.kt:48)
        at de.nwuensche.myapplication.MainActivity.lambda$m1NzZeOm-GuB9bgKAG9k7oILWF0(Unknown Source:0)
        at de.nwuensche.myapplication.-$$Lambda$MainActivity$m1NzZeOm-GuB9bgKAG9k7oILWF0.call(Unknown Source:2)
        at io.reactivex.internal.operators.single.SingleFromCallable.subscribeActual(SingleFromCallable.java:44)
        at io.reactivex.Single.subscribe(Single.java:3603) 
        at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89) 
        at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578) 
        at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66) 
        at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:923) 
     Caused by: com.bumptech.glide.load.engine.GlideException: Failed to load resource
sjudd commented 3 years ago

downloadOnly requires the disk cache because the disk cache is what's used to store the downloaded file. downloadOnly is kind of a specialized use case. If you're just downloading the original unmodified File, there's really not much benefit in using Glide. I'd recommend just downloading it directly using whatever networking library you've chosen.