Fix thread unsafe collecting of matching -dontwarn patterns

Fixes: b/401428591
Change-Id: I42abbe913a9b94e73ab3a60f8ec1fc29ea13a38b
diff --git a/src/main/java/com/android/tools/r8/errors/dontwarn/NonEmptyDontWarnConfiguration.java b/src/main/java/com/android/tools/r8/errors/dontwarn/NonEmptyDontWarnConfiguration.java
index ae31723..65bc2b4 100644
--- a/src/main/java/com/android/tools/r8/errors/dontwarn/NonEmptyDontWarnConfiguration.java
+++ b/src/main/java/com/android/tools/r8/errors/dontwarn/NonEmptyDontWarnConfiguration.java
@@ -32,19 +32,18 @@
   public boolean matches(DexType type) {
     for (ProguardClassNameList dontWarnPattern : dontWarnPatterns) {
       if (dontWarnPattern.matches(type)) {
-        recordMatch(dontWarnPattern, type);
+        assert recordMatch(dontWarnPattern, type);
         return true;
       }
     }
     return false;
   }
 
-  private void recordMatch(ProguardClassNameList dontWarnPattern, DexType type) {
-    if (InternalOptions.assertionsEnabled()) {
-      matchedDontWarnPatterns
-          .computeIfAbsent(dontWarnPattern, ignore -> Sets.newIdentityHashSet())
-          .add(type);
-    }
+  private synchronized boolean recordMatch(ProguardClassNameList dontWarnPattern, DexType type) {
+    matchedDontWarnPatterns
+        .computeIfAbsent(dontWarnPattern, ignore -> Sets.newIdentityHashSet())
+        .add(type);
+    return true;
   }
 
   @Override