Dbrant has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/315954

Change subject: Fix possible crash due to null CookieManager.
......................................................................

Fix possible crash due to null CookieManager.

Although I've been unable to reproduce it, I'm fairly sure about the cause
of this crash:

Inside OkHttpConnectionFactory, we initialize the CLIENT statically.
However, the instance of the client depends on the cookieManager to be
initialized in WikipediaApp, *but* the initialization of the cookieManager
only happens in onCreate(). This leaves open a possibility of CLIENT to be
initialized while cookieManager is still null.

This patch switches to initializing the CLIENT lazily, ensuring that the
cookieManager will have been initialized prior to any access of the
client.

Bug: T148172
Change-Id: Ieb16b0f4b9ea85eeabfb6923417f9bc3d9a85b94
---
M app/src/main/java/org/wikipedia/OkHttpConnectionFactory.java
1 file changed, 4 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/54/315954/1

diff --git a/app/src/main/java/org/wikipedia/OkHttpConnectionFactory.java 
b/app/src/main/java/org/wikipedia/OkHttpConnectionFactory.java
index 8c363f0..a6f0521 100644
--- a/app/src/main/java/org/wikipedia/OkHttpConnectionFactory.java
+++ b/app/src/main/java/org/wikipedia/OkHttpConnectionFactory.java
@@ -24,7 +24,7 @@
 public class OkHttpConnectionFactory implements HttpRequest.ConnectionFactory {
     private static final long HTTP_CACHE_SIZE = 64 * 1024 * 1024;
     private static final Cache HTTP_CACHE = new 
Cache(WikipediaApp.getInstance().getCacheDir(), HTTP_CACHE_SIZE);
-    @NonNull private static final OkHttpClient CLIENT = createClient();
+    private static OkHttpClient CLIENT;
 
     @Override
     public HttpURLConnection create(URL url) throws IOException {
@@ -39,6 +39,9 @@
 
     @NonNull
     public static OkHttpClient getClient() {
+        if (CLIENT == null) {
+            CLIENT = createClient();
+        }
         return CLIENT;
     }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/315954
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieb16b0f4b9ea85eeabfb6923417f9bc3d9a85b94
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <dbr...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to