From f3e6ae02fca315e0846f68e94574aa75535d6bbc Mon Sep 17 00:00:00 2001 From: Danilo Ercoli Date: Wed, 16 Oct 2019 15:10:40 +0200 Subject: [PATCH 1/4] Detect the ArrayIndexOutOfBoundsException exception on Android 8 and report it to the parent app --- .../org/wordpress/aztec/AztecExceptionHandler.kt | 13 +++++++++++++ ...ynamicLayoutGetBlockIndexOutOfBoundsException.kt | 5 +++++ 2 files changed, 18 insertions(+) create mode 100644 aztec/src/main/kotlin/org/wordpress/aztec/util/DynamicLayoutGetBlockIndexOutOfBoundsException.kt diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt index f5aff8547..189871ad4 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.util.DynamicLayoutGetBlockIndexOutOfBoundsException import org.wordpress.aztec.util.AztecLog import java.lang.Thread.UncaughtExceptionHandler @@ -42,6 +45,16 @@ 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1 + && ex is ArrayIndexOutOfBoundsException) { + val stackTrace = Log.getStackTraceString(ex) + if (stackTrace.contains("android.text.DynamicLayout.getBlockIndex(DynamicLayout.java:646)")) { + visualEditor.externalLogger?.logException(DynamicLayoutGetBlockIndexOutOfBoundsException("Error #8828", ex)) + } + } + rootHandler?.uncaughtException(thread, ex) } diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/util/DynamicLayoutGetBlockIndexOutOfBoundsException.kt b/aztec/src/main/kotlin/org/wordpress/aztec/util/DynamicLayoutGetBlockIndexOutOfBoundsException.kt new file mode 100644 index 000000000..17aa0d109 --- /dev/null +++ b/aztec/src/main/kotlin/org/wordpress/aztec/util/DynamicLayoutGetBlockIndexOutOfBoundsException.kt @@ -0,0 +1,5 @@ +package org.wordpress.aztec.util + +import java.lang.RuntimeException + +class DynamicLayoutGetBlockIndexOutOfBoundsException(message:String, cause:Throwable): RuntimeException(message, cause) \ No newline at end of file From 23f6d3b02f9c74207c3590cfc571667fda25b42f Mon Sep 17 00:00:00 2001 From: Danilo Ercoli Date: Wed, 16 Oct 2019 15:41:54 +0200 Subject: [PATCH 2/4] Fix lint --- .../util/DynamicLayoutGetBlockIndexOutOfBoundsException.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/util/DynamicLayoutGetBlockIndexOutOfBoundsException.kt b/aztec/src/main/kotlin/org/wordpress/aztec/util/DynamicLayoutGetBlockIndexOutOfBoundsException.kt index 17aa0d109..9b5990df3 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/util/DynamicLayoutGetBlockIndexOutOfBoundsException.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/util/DynamicLayoutGetBlockIndexOutOfBoundsException.kt @@ -2,4 +2,4 @@ package org.wordpress.aztec.util import java.lang.RuntimeException -class DynamicLayoutGetBlockIndexOutOfBoundsException(message:String, cause:Throwable): RuntimeException(message, cause) \ No newline at end of file +class DynamicLayoutGetBlockIndexOutOfBoundsException(message: String, cause: Throwable) : RuntimeException(message, cause) \ No newline at end of file From 876ac04b4b55304cb81dab7b5025822e4ddec2f8 Mon Sep 17 00:00:00 2001 From: Danilo Ercoli Date: Wed, 16 Oct 2019 16:42:46 +0200 Subject: [PATCH 3/4] Create a new package `org.wordpress.aztec.exceptions` and move DynamicLayoutGetBlockIndexOutOfBoundsException there --- .../main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt | 2 +- .../DynamicLayoutGetBlockIndexOutOfBoundsException.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename aztec/src/main/kotlin/org/wordpress/aztec/{util => exceptions}/DynamicLayoutGetBlockIndexOutOfBoundsException.kt (80%) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt index 189871ad4..f0288a654 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt @@ -3,7 +3,7 @@ package org.wordpress.aztec import android.os.Build import android.util.Log import org.wordpress.android.util.AppLog -import org.wordpress.aztec.util.DynamicLayoutGetBlockIndexOutOfBoundsException +import org.wordpress.aztec.exceptions.DynamicLayoutGetBlockIndexOutOfBoundsException import org.wordpress.aztec.util.AztecLog import java.lang.Thread.UncaughtExceptionHandler diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/util/DynamicLayoutGetBlockIndexOutOfBoundsException.kt b/aztec/src/main/kotlin/org/wordpress/aztec/exceptions/DynamicLayoutGetBlockIndexOutOfBoundsException.kt similarity index 80% rename from aztec/src/main/kotlin/org/wordpress/aztec/util/DynamicLayoutGetBlockIndexOutOfBoundsException.kt rename to aztec/src/main/kotlin/org/wordpress/aztec/exceptions/DynamicLayoutGetBlockIndexOutOfBoundsException.kt index 9b5990df3..c0f8499e8 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/util/DynamicLayoutGetBlockIndexOutOfBoundsException.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/exceptions/DynamicLayoutGetBlockIndexOutOfBoundsException.kt @@ -1,4 +1,4 @@ -package org.wordpress.aztec.util +package org.wordpress.aztec.exceptions import java.lang.RuntimeException From 86a000026a6de29e178e0fa4901c0d68e3adb30d Mon Sep 17 00:00:00 2001 From: Danilo Ercoli Date: Fri, 18 Oct 2019 19:51:59 +0200 Subject: [PATCH 4/4] Make sure to properly detect the error on Android 8.1 --- .../org/wordpress/aztec/AztecExceptionHandler.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt index f0288a654..fd7f633ee 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt @@ -47,10 +47,17 @@ 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1 - && ex is ArrayIndexOutOfBoundsException) { + if (ex is ArrayIndexOutOfBoundsException) { val stackTrace = Log.getStackTraceString(ex) - if (stackTrace.contains("android.text.DynamicLayout.getBlockIndex(DynamicLayout.java:646)")) { + 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)) } }