diff --git a/java/com/facebook/soloader/SoLoader.java b/java/com/facebook/soloader/SoLoader.java index 11eb942..1273843 100644 --- a/java/com/facebook/soloader/SoLoader.java +++ b/java/com/facebook/soloader/SoLoader.java @@ -92,7 +92,7 @@ public class SoLoader { */ @GuardedBy("sSoSourcesLock") @Nullable - private static SoSource[] sSoSources = null; + private static volatile SoSource[] sSoSources = null; @GuardedBy("sSoSourcesLock") private static final AtomicInteger sSoSourcesVersion = new AtomicInteger(0); @@ -278,6 +278,13 @@ private static void initSoSources(Context context, int flags, String[] denyList) } sSoSourcesLock.writeLock().lock(); + + // Double check that sSoSources wasn't initialized while waiting for the lock. + if (sSoSources != null) { + sSoSourcesLock.writeLock().unlock(); + return; + } + try { sFlags = flags;