<p dir="auto"><strong>Glide Version</strong>: 4.12.0</p>

<p dir="auto"><strong>Integration libraries</strong>: okhttp3-4.9.0</p>

<p dir="auto"><strong>Device/Android Version</strong>: OPPO A5/Android8.1.0</p>

<p dir="auto"><strong>Issue details / Repro steps / Use case background</strong>:</p>

<p dir="auto"><strong>Glide load line / <code class="notranslate">GlideModule</code> (if any) / list Adapter code (if any)</strong>:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Glide.with..."><pre class="notranslate"><span class="pl-smi">Glide</span>.<span class="pl-smi">with</span>...</pre></div>

<p dir="auto"><strong>Layout XML</strong>:</p>
<div class="highlight highlight-text-xml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;FrameLayout xmlns:android=&quot;..."><pre class="notranslate">&lt;<span class="pl-ent">FrameLayout</span> <span class="pl-e">xmlns</span><span class="pl-e">:</span><span class="pl-e">android</span>=<span class="pl-s"><span class="pl-pds">"</span>...</span></pre></div>

<p dir="auto"><strong>Stack trace / LogCat</strong>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
# main(2)

java.lang.NullPointerException

Attempt to read from field 'com.bumptech.glide.load.engine.DecodeJob$DiskCacheProvider com.bumptech.glide.load.engine.Engine$DecodeJobFactory.diskCacheProvider' on a null object reference

1
com.bumptech.glide.load.engine.Engine$DecodeJobFactory$1.create(Engine.java:483)
2
com.bumptech.glide.load.engine.Engine$DecodeJobFactory$1.create(Engine.java:480)
3
com.bumptech.glide.util.pool.FactoryPools$FactoryPool.acquire(FactoryPools.java:163)
4
com.bumptech.glide.load.engine.Engine$DecodeJobFactory.build(Engine.java:511)
5
com.bumptech.glide.load.engine.Engine.waitForExistingOrStartNewJob(Engine.java:266)
6
com.bumptech.glide.load.engine.Engine.load(Engine.java:193)
7
com.bumptech.glide.request.SingleRequest.onSizeReady(SingleRequest.java:451)
8
com.bumptech.glide.request.target.ViewTarget$SizeDeterminer.notifyCbs(ViewTarget.java:352)
9
com.bumptech.glide.request.target.ViewTarget$SizeDeterminer.checkCurrentDimens(ViewTarget.java:368)
10
com.bumptech.glide.request.target.ViewTarget$SizeDeterminer$SizeDeterminerLayoutListener.onPreDraw(ViewTarget.java:513)
11
android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
12
android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2772)
13
android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1718)
14
android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7513)
15
android.view.Choreographer$CallbackRecord.run(Choreographer.java:1066)
16
android.view.Choreographer.doCallbacks(Choreographer.java:878)
17
android.view.Choreographer.doFrame(Choreographer.java:794)
18
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1052)
19
android.os.Handler.handleCallback(Handler.java:790)
20
android.os.Handler.dispatchMessage(Handler.java:99)
21
android.os.Looper.loop(Looper.java:210)
22
android.app.ActivityThread.main(ActivityThread.java:7080)
23
java.lang.reflect.Method.invoke(Native Method)
24
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:523)
25
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:863)"><pre class="notranslate"><code class="notranslate">
# main(2)

java.lang.NullPointerException

Attempt to read from field 'com.bumptech.glide.load.engine.DecodeJob$DiskCacheProvider com.bumptech.glide.load.engine.Engine$DecodeJobFactory.diskCacheProvider' on a null object reference

1
com.bumptech.glide.load.engine.Engine$DecodeJobFactory$1.create(Engine.java:483)
2
com.bumptech.glide.load.engine.Engine$DecodeJobFactory$1.create(Engine.java:480)
3
com.bumptech.glide.util.pool.FactoryPools$FactoryPool.acquire(FactoryPools.java:163)
4
com.bumptech.glide.load.engine.Engine$DecodeJobFactory.build(Engine.java:511)
5
com.bumptech.glide.load.engine.Engine.waitForExistingOrStartNewJob(Engine.java:266)
6
com.bumptech.glide.load.engine.Engine.load(Engine.java:193)
7
com.bumptech.glide.request.SingleRequest.onSizeReady(SingleRequest.java:451)
8
com.bumptech.glide.request.target.ViewTarget$SizeDeterminer.notifyCbs(ViewTarget.java:352)
9
com.bumptech.glide.request.target.ViewTarget$SizeDeterminer.checkCurrentDimens(ViewTarget.java:368)
10
com.bumptech.glide.request.target.ViewTarget$SizeDeterminer$SizeDeterminerLayoutListener.onPreDraw(ViewTarget.java:513)
11
android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
12
android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2772)
13
android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1718)
14
android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7513)
15
android.view.Choreographer$CallbackRecord.run(Choreographer.java:1066)
16
android.view.Choreographer.doCallbacks(Choreographer.java:878)
17
android.view.Choreographer.doFrame(Choreographer.java:794)
18
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1052)
19
android.os.Handler.handleCallback(Handler.java:790)
20
android.os.Handler.dispatchMessage(Handler.java:99)
21
android.os.Looper.loop(Looper.java:210)
22
android.app.ActivityThread.main(ActivityThread.java:7080)
23
java.lang.reflect.Method.invoke(Native Method)
24
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:523)
25
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:863)
</code></pre></div>
<p dir="auto">I would like to find a way to cache the webview images myself, as some of them may be used in the future in an imageview. Currently, I can find out when an image will be loaded and get its url through the webview's <code class="notranslate">shouldInterceptRequest</code>.</p>
<p dir="auto">I've tried using Glide's <code class="notranslate">submit</code> call, but the loading is significantly slower. I've also noticed that calling it this way still makes the request check on the ui thread if the webview is valid before proceeding, which may add notable overhead to so many requests. Is there any way to improve this?</p>
<p dir="auto">My web response:</p>
<div class="highlight highlight-source-kotlin notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class FrostImageResponse(view: WebView, url: String) : WebResourceResponse(&quot;&quot;, &quot;&quot;, null) {

    val futureBitmap = GlideApp.with(view).asBitmap().load(url).submit()

    override fun getData(): InputStream {
        val bos = ByteArrayOutputStream()
        futureBitmap.get().compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos)
        val bitmapdata = bos.toByteArray()
        return ByteArrayInputStream(bitmapdata)
    }
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-en">FrostImageResponse</span>(<span class="pl-smi">view</span><span class="pl-k">:</span> <span class="pl-en">WebView</span>, <span class="pl-smi">url</span><span class="pl-k">:</span> <span class="pl-c1">String</span>) : WebResourceResponse(<span class="pl-s"><span class="pl-pds">"</span><span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span><span class="pl-pds">"</span></span>, <span class="pl-c1">null</span>) {

    <span class="pl-k">val</span> futureBitmap <span class="pl-k">=</span> <span class="pl-en">GlideApp</span>.<span class="pl-c1">with</span>(view).asBitmap().load(url).submit()

    <span class="pl-k">override</span> <span class="pl-k">fun</span> <span class="pl-en">getData</span>(): <span class="pl-en">InputStream</span> {
        <span class="pl-k">val</span> bos <span class="pl-k">=</span> <span class="pl-en">ByteArrayOutputStream</span>()
        futureBitmap.get().compress(<span class="pl-en">CompressFormat</span>.<span class="pl-en">PNG</span>, <span class="pl-c1">0</span> <span class="pl-c"><span class="pl-c">/*</span>ignored for PNG<span class="pl-c">*/</span></span>, bos)
        <span class="pl-k">val</span> bitmapdata <span class="pl-k">=</span> bos.toByteArray()
        <span class="pl-k">return</span> <span class="pl-en">ByteArrayInputStream</span>(bitmapdata)
    }
}</pre></div>