Skip to content

Commit 6ae6fda

Browse files
committed
Make sure we clear references in the AztecExceptionHandler.kt when the handler is disabled
1 parent f230855 commit 6ae6fda

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.wordpress.aztec.exceptions.DynamicLayoutGetBlockIndexOutOfBoundsExcep
77
import org.wordpress.aztec.util.AztecLog
88
import java.lang.Thread.UncaughtExceptionHandler
99

10-
class AztecExceptionHandler(private val logHelper: ExceptionHandlerHelper?, private val visualEditor: AztecText) : UncaughtExceptionHandler {
10+
class AztecExceptionHandler(private var logHelper: ExceptionHandlerHelper?, private var visualEditor: AztecText?) : UncaughtExceptionHandler {
1111

1212
interface ExceptionHandlerHelper {
1313
fun shouldLog(ex: Throwable) : Boolean
@@ -34,12 +34,14 @@ class AztecExceptionHandler(private val logHelper: ExceptionHandlerHelper?, priv
3434
// Try to report the HTML code of the content, the spans details, but do not report exceptions that can occur logging the content
3535
try {
3636
AppLog.e(AppLog.T.EDITOR, "HTML content of Aztec Editor before the crash:")
37-
AppLog.e(AppLog.T.EDITOR, visualEditor.toPlainHtml(false))
37+
AppLog.e(AppLog.T.EDITOR, visualEditor?.toPlainHtml(false) ?: "Editor was cleared")
3838
} catch (e: Throwable) {
3939
AppLog.e(AppLog.T.EDITOR, "Oops! There was an error logging the HTML code.")
4040
}
4141
try {
42-
AztecLog.logContentDetails(visualEditor)
42+
visualEditor?.let {
43+
AztecLog.logContentDetails(it)
44+
}
4345
} catch (e: Throwable) {
4446
// nop
4547
}
@@ -58,14 +60,16 @@ class AztecExceptionHandler(private val logHelper: ExceptionHandlerHelper?, priv
5860
detected = true
5961
}
6062
if (detected) {
61-
visualEditor.externalLogger?.logException(DynamicLayoutGetBlockIndexOutOfBoundsException("Error #8828", ex))
63+
visualEditor?.externalLogger?.logException(DynamicLayoutGetBlockIndexOutOfBoundsException("Error #8828", ex))
6264
}
6365
}
6466

6567
rootHandler?.uncaughtException(thread, ex)
6668
}
6769

6870
fun restoreDefaultHandler() {
71+
visualEditor = null
72+
logHelper = null
6973
Thread.setDefaultUncaughtExceptionHandler(rootHandler)
7074
}
7175
}

0 commit comments

Comments
 (0)