Repository: square/leakcanary
Issue: Android 9 crash in debug build, version leackcanary 2.4

### Description
crash in open inner fragment my pet project
### step
 1 debugImplementation(Libs.leakcanary) version 2.4
 2 open inner fragment

// version 2.2 work  this case 
// code can give this repeat pet project 

### result 
```
 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.yweber.mathquickcount, PID: 3193
    java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
        at android.content.res.AssetManager.getPooledStringForCookie(AssetManager.java:828)
        at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:1334)
        at android.content.res.TypedArray.getString(TypedArray.java:236)
        at android.view.View.saveAttributeData(View.java:5790)
        at android.view.View.<init>(View.java:4998)
        at android.view.ViewGroup.<init>(ViewGroup.java:659)
        at android.view.ViewGroup.<init>(ViewGroup.java:655)
        at android.view.ViewGroup.<init>(ViewGroup.java:651)
        at android.view.ViewGroup.<init>(ViewGroup.java:647)
        at android.widget.FrameLayout.<init>(FrameLayout.java:78)
        at leakcanary.ViewLocationHolderLeakFix.uncheckedClearStaticPool(ViewLocationHolderLeakFix.kt:57)
        at leakcanary.ViewLocationHolderLeakFix.access$uncheckedClearStaticPool(ViewLocationHolderLeakFix.kt:18)
        at leakcanary.ViewLocationHolderLeakFix$applyFix$1$onActivityCreated$1.invoke(ViewLocationHolderLeakFix.kt:34)
        at leakcanary.ViewLocationHolderLeakFix$applyFix$1$onActivityCreated$1.invoke(ViewLocationHolderLeakFix.kt:26)
        at leakcanary.internal.FragmentExtensionsKt$onAndroidXFragmentViewDestroyed$1.onFragmentViewDestroyed(FragmentExtensions.kt:28)
        at androidx.fragment.app.FragmentLifecycleCallbacksDispatcher.dispatchOnFragmentViewDestroyed(FragmentLifecycleCallbacksDispatcher.java:265)
        at androidx.fragment.app.FragmentManager.destroyFragmentView(FragmentManager.java:1357)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1276)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1368)
        at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1446)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1516)
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2019)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1965)
        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1861)
        at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
        at android.os.Handler.handleCallback(Handler.java:907)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7625)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
```


Changed files:
plumber-android/src/main/java/leakcanary/ViewLocationHolderLeakFix.kt

diff --git a/plumber-android/src/main/java/leakcanary/ViewLocationHolderLeakFix.kt b/plumber-android/src/main/java/leakcanary/ViewLocationHolderLeakFix.kt
index e6d76b4c3..4d2267315 100644
--- a/plumber-android/src/main/java/leakcanary/ViewLocationHolderLeakFix.kt
+++ b/plumber-android/src/main/java/leakcanary/ViewLocationHolderLeakFix.kt
@@ -10,6 +10,7 @@ import android.view.ViewGroup
 import android.widget.FrameLayout
 import leakcanary.AndroidLeakFixes.Companion.checkMainThread
 import leakcanary.internal.onAndroidXFragmentViewDestroyed
+import shark.SharkLog
 
 /**
  * @see [AndroidLeakFixes.VIEW_LOCATION_HOLDER].
@@ -18,6 +19,7 @@ import leakcanary.internal.onAndroidXFragmentViewDestroyed
 object ViewLocationHolderLeakFix {
 
   private var groupAndOutChildren: Pair<ViewGroup, ArrayList<View>>? = null
+  private var failedClearing = false
 
   internal fun applyFix(application: Application) {
     if (VERSION.SDK_INT != 28) {
@@ -53,16 +55,26 @@ object ViewLocationHolderLeakFix {
   }
 
   private fun uncheckedClearStaticPool(application: Application) {
-    if (groupAndOutChildren == null) {
-      val viewGroup = FrameLayout(application)
-      // ViewLocationHolder.MAX_POOL_SIZE = 32
-      for (i in 0 until 32) {
-        val childView = View(application)
-        viewGroup.addView(childView)
+    if (failedClearing) {
+      return
+    }
+    try {
+      if (groupAndOutChildren == null) {
+        val viewGroup = FrameLayout(application)
+        // ViewLocationHolder.MAX_POOL_SIZE = 32
+        for (i in 0 until 32) {
+          val childView = View(application)
+          viewGroup.addView(childView)
+        }
+        groupAndOutChildren = viewGroup to ArrayList()
+      }
+      val (group, outChildren) = groupAndOutChildren!!
+      group.addChildrenForAccessibility(outChildren)
+    } catch (ignored :Throwable) {
+      SharkLog.d(ignored) {
+        "Failed to clear ViewLocationHolder leak, will not try again."
       }
-      groupAndOutChildren = viewGroup to ArrayList()
+      failedClearing = true
     }
-    val (group, outChildren) = groupAndOutChildren!!
-    group.addChildrenForAccessibility(outChildren)
   }
 }