diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt index f5aff8547..fd7f633ee 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt @@ -1,6 +1,9 @@ package org.wordpress.aztec +import android.os.Build +import android.util.Log import org.wordpress.android.util.AppLog +import org.wordpress.aztec.exceptions.DynamicLayoutGetBlockIndexOutOfBoundsException import org.wordpress.aztec.util.AztecLog import java.lang.Thread.UncaughtExceptionHandler @@ -42,6 +45,23 @@ class AztecExceptionHandler(private val logHelper: ExceptionHandlerHelper?, priv } } + // Detect ArrayIndexOutOfBoundsException on Android 8, and report it to the parent app + // See: https://github.com/wordpress-mobile/WordPress-Android/issues/8828 + if (ex is ArrayIndexOutOfBoundsException) { + val stackTrace = Log.getStackTraceString(ex) + var detected = false + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O && + stackTrace.contains("android.text.DynamicLayout.getBlockIndex(DynamicLayout.java:646)")) { + detected = true + } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O_MR1 && + stackTrace.contains("android.text.DynamicLayout.getBlockIndex(DynamicLayout.java:648)")) { + detected = true + } + if (detected) { + visualEditor.externalLogger?.logException(DynamicLayoutGetBlockIndexOutOfBoundsException("Error #8828", ex)) + } + } + rootHandler?.uncaughtException(thread, ex) } diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/exceptions/DynamicLayoutGetBlockIndexOutOfBoundsException.kt b/aztec/src/main/kotlin/org/wordpress/aztec/exceptions/DynamicLayoutGetBlockIndexOutOfBoundsException.kt new file mode 100644 index 000000000..c0f8499e8 --- /dev/null +++ b/aztec/src/main/kotlin/org/wordpress/aztec/exceptions/DynamicLayoutGetBlockIndexOutOfBoundsException.kt @@ -0,0 +1,5 @@ +package org.wordpress.aztec.exceptions + +import java.lang.RuntimeException + +class DynamicLayoutGetBlockIndexOutOfBoundsException(message: String, cause: Throwable) : RuntimeException(message, cause) \ No newline at end of file