Skip to content

Commit

Permalink
Merge pull request #861 from wordpress-mobile/issue/wp-android-8828-A…
Browse files Browse the repository at this point in the history
…rrayIndexOutOfBoundsException

[WP-Android 8828] - Detect ArrayIndexOutOfBoundsException exception
  • Loading branch information
daniloercoli authored Oct 22, 2019
2 parents c3293b1 + 86a0000 commit f5ce89c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.wordpress.aztec.exceptions

import java.lang.RuntimeException

class DynamicLayoutGetBlockIndexOutOfBoundsException(message: String, cause: Throwable) : RuntimeException(message, cause)

0 comments on commit f5ce89c

Please sign in to comment.