Snap for 5358809 from 4fb8e848f64ed594fda378e6aa695dacf29c06d4 to studio-3.4-release

Change-Id: I514f52eaf3c1ea31e1aed88ea5d9e58282cba8ae
diff --git a/compilerCommon/src/main/kotlin/android/databinding/tool/LibTypes.kt b/compilerCommon/src/main/kotlin/android/databinding/tool/LibTypes.kt
index 4315d5e..01e2388 100644
--- a/compilerCommon/src/main/kotlin/android/databinding/tool/LibTypes.kt
+++ b/compilerCommon/src/main/kotlin/android/databinding/tool/LibTypes.kt
@@ -26,12 +26,15 @@
     } else {
         "android.databinding"
     }
+
     private val typeRewriter by lazy(LazyThreadSafetyMode.NONE) {
-        val config = ConfigParser.loadDefaultConfig()
+        // Since subprojects with data binding can be built in parallel and loading the Jetifier
+        // config below is not thread-safe, we need to use a lock (see bug 123984697 for more info).
+        val config = synchronized(lockForConfigParser) {
+             ConfigParser.loadDefaultConfig()
                 ?: throw IllegalStateException("Cannot load AndroidX conversion file.")
-        TypeRewriter(
-                config = config,
-                useFallback = true)
+        }
+        TypeRewriter(config = config, useFallback = true)
     }
 
     val viewStubProxy by lazy(LazyThreadSafetyMode.NONE) {
@@ -188,6 +191,10 @@
     }
 
     companion object {
+        // Lock for loading the Jetifier config. (We assume that there is a 1-1 mapping between
+        // between this LibTypes class and the Jetifier ConfigParser class.)
+        private val lockForConfigParser = Object()
+
         // needed until we can update jettifier w/ arch and data binding
         private val PREFIX_REPLACEMENTS = mapOf(
                 "android.databinding." to "androidx.databinding.",