Skip to content

Commit 79eddba

Browse files
authored
Merge pull request #1071 from wordpress-mobile/refactor/guard-previousfontmetrics-against-null
Address `NullPointerException` crash in `AztecHeadingSpan`
2 parents d93ce9f + 6dd6bc5 commit 79eddba

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHeadingSpan.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ open class AztecHeadingSpan(
127127
// save original font metrics
128128
if (previousFontMetrics == null) {
129129
previousFontMetrics = Paint.FontMetricsInt()
130-
previousFontMetrics!!.top = fm.top
131-
previousFontMetrics!!.ascent = fm.ascent
132-
previousFontMetrics!!.bottom = fm.bottom
133-
previousFontMetrics!!.descent = fm.descent
130+
previousFontMetrics?.top = fm.top
131+
previousFontMetrics?.ascent = fm.ascent
132+
previousFontMetrics?.bottom = fm.bottom
133+
previousFontMetrics?.descent = fm.descent
134134
}
135135

136136
var addedTopPadding = false
@@ -151,13 +151,17 @@ open class AztecHeadingSpan(
151151

152152
// apply original font metrics to lines that should not have vertical padding
153153
if (!addedTopPadding) {
154-
fm.ascent = previousFontMetrics!!.ascent
155-
fm.top = previousFontMetrics!!.top
154+
previousFontMetrics?.let {
155+
fm.ascent = it.ascent
156+
fm.top = it.top
157+
}
156158
}
157159

158160
if (!addedBottomPadding) {
159-
fm.descent = previousFontMetrics!!.descent
160-
fm.bottom = previousFontMetrics!!.bottom
161+
previousFontMetrics?.let {
162+
fm.descent = it.descent
163+
fm.bottom = it.bottom
164+
}
161165
}
162166
}
163167

0 commit comments

Comments
 (0)