Skip to content

Commit 42c1ece

Browse files
committed
Make sure to log errors happeing in toString routine.
1 parent 539f208 commit 42c1ece

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ class AztecAttributes(attributes: Attributes = AttributesImpl()) : AttributesImp
2323
}
2424

2525
private fun logInternalState() {
26-
AppLog.e(AppLog.T.EDITOR, "AttributesImpl has an internal length of $length")
27-
// Since we're not sure the internal state of the Obj is correct we're wrapping toString in a try/catch
26+
AppLog.e(AppLog.T.EDITOR, "Dumping internal state:")
27+
AppLog.e(AppLog.T.EDITOR, "length = $length")
28+
// Since the toString can throw OOB error we need to wrap it in a try/catch
2829
try {
29-
AppLog.e(AppLog.T.EDITOR, "Dumping internal state:")
3030
AppLog.e(AppLog.T.EDITOR, toString())
31-
} catch (t: Throwable) {
32-
AppLog.e(AppLog.T.EDITOR, "Error dumping internal state!")
31+
} catch (e: ArrayIndexOutOfBoundsException) {
32+
AppLog.e(AppLog.T.EDITOR, "Error dumping internal state!", e)
3333
}
3434
}
3535

@@ -58,12 +58,20 @@ class AztecAttributes(attributes: Attributes = AttributesImpl()) : AttributesImp
5858

5959
override fun toString(): String {
6060
val sb = StringBuilder()
61-
for (i in 0..this.length - 1) {
62-
sb.append(this.getLocalName(i))
63-
sb.append("=\"")
64-
sb.append(this.getValue(i))
65-
sb.append("\" ")
61+
try {
62+
for (i in 0..this.length - 1) {
63+
sb.append(this.getLocalName(i))
64+
sb.append("=\"")
65+
sb.append(this.getValue(i))
66+
sb.append("\" ")
67+
}
68+
} catch (e: ArrayIndexOutOfBoundsException) {
69+
// https://github.com/wordpress-mobile/AztecEditor-Android/issues/705
70+
AppLog.e(AppLog.T.EDITOR, "IOOB occurred in toString. Dumping partial state:")
71+
AppLog.e(AppLog.T.EDITOR, sb.trimEnd().toString())
72+
throw e
6673
}
74+
6775
return sb.trimEnd().toString()
6876
}
6977
}

0 commit comments

Comments
 (0)