-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WP-Android 8828] - Detect ArrayIndexOutOfBoundsException exception #861
[WP-Android 8828] - Detect ArrayIndexOutOfBoundsException exception #861
Conversation
…report it to the parent app
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)")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice checking for the line number string here. It makes it fine-grained so we avoid having false positives treated mistakingly 👍
Also, was wondering whether stackTrace
could be null, so double checked getStackTraceString()
and it seems it will never return null
as per this so 👍 as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I detected an issue - this line will be different on Android 8.1 (API 27), see this #516
it will be java.lang.ArrayIndexOutOfBoundsException: length=39; index=-1 at android.text.DynamicLayout.getBlockIndex(DynamicLayout.java:648)
If you follow the steps to reproduce in the comment below on Android 8.1 (API 27) it will fail the string comparison @daniloercoli - can we add this other string for the case where Build.VERSION.SDK_INT == Build.VERSION_CODES.O_MR1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! I've updated the code in 86a0000
Tried to be more verbose as possibile to let future devs to understand quickly why there are those if cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thank you 🙇
@@ -0,0 +1,5 @@ | |||
package org.wordpress.aztec.util |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about moving this class to a package of its own like org.wordpress.aztec.exception
or org.wordpress.aztec.util.exception
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea. Addressed in 876ac04
…cLayoutGetBlockIndexOutOfBoundsException there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
FYI just wanted to leave a note that this is easily reproduceable (so the code in this PR can be tested) by disabling the Comment out lines 528 in AztecText.kt like this:
Only leave Then follow these steps:
I've tested it and confirmed the crash is captured by the code in this branch and the call to the external logger is correctly made 👍 |
How can we catch the ArrayIndexOutOfBoundsException exception? |
This PR does add the ability to detect the
ArrayIndexOutOfBoundsException
that may happen on Android 8 at the following line of codeandroid.text.DynamicLayout.getBlockIndex(DynamicLayout.java:646)
due to a bug present in the Android Platform.When this exact exception is detected, Aztec reports it to the parent app, by wrapping it into a custom Exception.
The reporting to the parent app happens by re-using the external logging capabilities of Aztec, instead of adding another layer of communication between Aztec and the parent app.
The parent app should just check the type of the exception in the "external" logger implementation passed to Aztec.
Make sure strings will be translated:
strings.xml
as a part of the integration PR.