Fix LRUCache table synchronisation

Fix red bots

Bug: b/242286733
Change-Id: I31a368fc85c7036cb443d445a555380206bedaff
diff --git a/src/main/java/com/android/tools/r8/ir/analysis/type/ClassTypeElement.java b/src/main/java/com/android/tools/r8/ir/analysis/type/ClassTypeElement.java
index 6101905..26993a6 100644
--- a/src/main/java/com/android/tools/r8/ir/analysis/type/ClassTypeElement.java
+++ b/src/main/java/com/android/tools/r8/ir/analysis/type/ClassTypeElement.java
@@ -479,14 +479,17 @@
     if (s1.isEmpty() || s2.isEmpty()) {
       return InterfaceCollection.empty();
     }
-    InterfaceCollection cached =
-        appView.dexItemFactory().leastUpperBoundOfInterfacesTable.get(s1, s2);
-    if (cached != null) {
-      return cached;
-    }
-    cached = appView.dexItemFactory().leastUpperBoundOfInterfacesTable.get(s2, s1);
-    if (cached != null) {
-      return cached;
+    // Synchronization is required, see b/242286733.
+    synchronized (appView.dexItemFactory().leastUpperBoundOfInterfacesTable) {
+      InterfaceCollection cached =
+          appView.dexItemFactory().leastUpperBoundOfInterfacesTable.get(s1, s2);
+      if (cached != null) {
+        return cached;
+      }
+      cached = appView.dexItemFactory().leastUpperBoundOfInterfacesTable.get(s2, s1);
+      if (cached != null) {
+        return cached;
+      }
     }
     Map<DexType, InterfaceMarker> seen = new IdentityHashMap<>();
     Queue<InterfaceWithMarker> worklist = new ArrayDeque<>();
diff --git a/src/main/java/com/android/tools/r8/utils/LRUCacheTable.java b/src/main/java/com/android/tools/r8/utils/LRUCacheTable.java
index 8c3fe7f..94b2fa4 100644
--- a/src/main/java/com/android/tools/r8/utils/LRUCacheTable.java
+++ b/src/main/java/com/android/tools/r8/utils/LRUCacheTable.java
@@ -51,14 +51,6 @@
     return getOrDefault(rowKey, ImmutableMap.of()).containsKey(columnKey);
   }
 
-  // TODO(b/242286733): Temporary bug mitigation, This class includes concurrent read/writes
-  //  leading to NullPointerException at runtime on some VMs/devices.
-  @Override
-  public Map<C, V> getOrDefault(Object key, Map<C, V> defaultValue) {
-    Map<C, V> cvMap = super.get(key);
-    return cvMap == null ? defaultValue : cvMap;
-  }
-
   public V get(R rowKey, C columnKey) {
     return getOrDefault(rowKey, ImmutableMap.of()).get(columnKey);
   }
diff --git a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/r8ondex/R8CompiledThroughDexTest.java b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/r8ondex/R8CompiledThroughDexTest.java
index b99b5c0..44eb8fa 100644
--- a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/r8ondex/R8CompiledThroughDexTest.java
+++ b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/r8ondex/R8CompiledThroughDexTest.java
@@ -55,10 +55,8 @@
     return buildParameters(
         getTestParameters()
             // Android 5 and 6 do not seem to work with more than 512 Mb of RAM.
-            .withDexRuntime(Version.V7_0_0)
+            .withDexRuntime(Version.V8_1_0)
             // TODO(b/241748003): Broken strictly below 19 due to charset issue.
-            // TODO(b/242286733): Broken strictly below 26 due to LinkedHashMap issue.
-            //  The LinkedHashMap issue is mitigated on 24-25.
             .withApiLevel(AndroidApiLevel.N)
             .build(),
         ImmutableList.of(JDK11_PATH),