Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Exception: java.lang.NullPointerException: okhttp3.Cache$Entry.readCertificateList #7978

Closed
Anigif opened this issue Aug 9, 2023 · 4 comments · Fixed by #7981 or #7982
Closed
Labels
bug Bug in existing code

Comments

@Anigif
Copy link

Anigif commented Aug 9, 2023

We have a few Android TV users (don't now it's related to Android TV) that gets a crash in a custom interceptor we have. Its not that many users but they are however getting this crash a lot.

This is an example of the stacktrace after we call proceed(), so I'm sure if we can do anything in our end (other than catching the exception):

Fatal Exception: java.lang.NullPointerException:
       at okhttp3.Cache$Entry.readCertificateList(Cache.kt:612)
       at okhttp3.Cache$Entry.<init>(Cache.kt:534)
       at okhttp3.Cache.get$okhttp(Cache.kt:178)
       at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:47)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       ...
@Anigif Anigif added the bug Bug in existing code label Aug 9, 2023
@yschimke
Copy link
Collaborator

yschimke commented Aug 9, 2023

Similar to #6260

@yschimke
Copy link
Collaborator

yschimke commented Aug 9, 2023

Presumably failing here https://github.com/square/okhttp/blob/okhttp_4x/okhttp/src/main/kotlin/okhttp3/Cache.kt#L612

        val certificateFactory = CertificateFactory.getInstance("X.509")
        val result = ArrayList<Certificate>(length)
        for (i in 0 until length) {
          val line = source.readUtf8LineStrict()
          val bytes = Buffer()
          bytes.write(line.decodeBase64()!!)
          result.add(certificateFactory.generateCertificate(bytes.inputStream()))
        }

I'll take a look after work.

@yschimke
Copy link
Collaborator

I can't see how it can happen, but even a corrupted cache file, causing base64 decode should fail, should be a IOException.

Will fix and backport to 4.x

@Anigif
Copy link
Author

Anigif commented Aug 10, 2023

Android TVs often work in mysterious ways! But sounds awesome you'll make a fix.

I forgot to mention at first, but in our project is using Retrofit 2.9.0 and have a reference to OkHttp 4.11.0 as well - not sure if that makes a difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in existing code
Projects
None yet
2 participants