Skip to content

Commit e7e3a18

Browse files
committed
Wrap setValue and removeAttribute with a try/catch statement and log the error.
1 parent f42061a commit e7e3a18

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecAttributes.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.wordpress.aztec
22

3+
import org.wordpress.android.util.AppLog
34
import org.xml.sax.Attributes
45
import org.xml.sax.helpers.AttributesImpl
56

@@ -9,7 +10,13 @@ class AztecAttributes(attributes: Attributes = AttributesImpl()) : AttributesImp
910
if (index == -1) {
1011
addAttribute("", key, key, "string", value)
1112
} else {
12-
setValue(index, value)
13+
try {
14+
setValue(index, value)
15+
} catch (e: ArrayIndexOutOfBoundsException) {
16+
// we should not be here since `getIndex(key)` checks if the attribute is already available or not,
17+
// but apparently...https://github.com/wordpress-mobile/AztecEditor-Android/issues/705
18+
AppLog.e(AppLog.T.EDITOR, "Tried to set attribute: $key at index: $index")
19+
}
1320
}
1421
}
1522

@@ -20,7 +27,14 @@ class AztecAttributes(attributes: Attributes = AttributesImpl()) : AttributesImp
2027
fun removeAttribute(key: String) {
2128
if (hasAttribute(key)) {
2229
val index = getIndex(key)
23-
removeAttribute(index)
30+
try {
31+
removeAttribute(index)
32+
} catch (e: ArrayIndexOutOfBoundsException) {
33+
// we should not be here since hasAttribute checked if the attribute is available or not,
34+
// but apparently...https://github.com/wordpress-mobile/AztecEditor-Android/issues/705
35+
AppLog.e(AppLog.T.EDITOR, "Tried to remove attribute: $key that is not in the list.")
36+
AppLog.e(AppLog.T.EDITOR, "Reported to be at index: $index")
37+
}
2438
}
2539
}
2640

0 commit comments

Comments
 (0)