From f84c332c9e860c2f4bb6b306baa5f2a9572e57de Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 18 Dec 2022 21:55:12 +0100 Subject: [PATCH] Prevent NPE --- app/src/main/java/eu/faircode/email/Helper.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index a98b286bb4..50c750ec5e 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -251,7 +251,7 @@ public class Helper { static ExecutorService sSerialTaskExecutor = null; static int sOperationIndex = 0; - static ExecutorService[] sOperationExecutor = new ExecutorService[OPERATION_WORKERS]; + static final ExecutorService[] sOperationExecutor = new ExecutorService[OPERATION_WORKERS]; static ExecutorService getSerialExecutor() { if (sSerialExecutor == null) @@ -272,11 +272,13 @@ public class Helper { } static ExecutorService getOperationExecutor() { - if (sOperationExecutor[sOperationIndex] == null) - sOperationExecutor[sOperationIndex] = getBackgroundExecutor(1, "operation"); - ExecutorService result = sOperationExecutor[sOperationIndex]; - sOperationIndex = (sOperationIndex + 1) % sOperationExecutor.length; - return result; + synchronized (sOperationExecutor) { + if (sOperationExecutor[sOperationIndex] == null) + sOperationExecutor[sOperationIndex] = getBackgroundExecutor(1, "operation"); + ExecutorService result = sOperationExecutor[sOperationIndex]; + sOperationIndex = (sOperationIndex + 1) % sOperationExecutor.length; + return result; + } } private static ExecutorService getBackgroundExecutor(int threads, final String name) {