From 21b8ba0a2adfecebb1fe77863ddb26788de3c8ac Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 27 Oct 2022 09:44:12 +0200 Subject: [PATCH] Prevent crash --- .../main/java/eu/faircode/email/HtmlEx.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlEx.java b/app/src/main/java/eu/faircode/email/HtmlEx.java index 0a31f49107..99967829b5 100644 --- a/app/src/main/java/eu/faircode/email/HtmlEx.java +++ b/app/src/main/java/eu/faircode/email/HtmlEx.java @@ -103,7 +103,7 @@ public class HtmlEx { int next; for (int i = 0; i < len; i = next) { - next = text.nextSpanTransition(i, len, ParagraphStyle.class); + next = nextSpanTransition(text, i, len, ParagraphStyle.class); ParagraphStyle[] style = getSpans(text, i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; @@ -138,8 +138,8 @@ public class HtmlEx { int option) { int next; for (int i = start; i < end; i = next) { - int n1 = text.nextSpanTransition(i, end, QuoteSpan.class); - int n2 = text.nextSpanTransition(i, end, eu.faircode.email.IndentSpan.class); + int n1 = nextSpanTransition(text, i, end, QuoteSpan.class); + int n2 = nextSpanTransition(text, i, end, eu.faircode.email.IndentSpan.class); next = Math.min(n1, n2); try { List spans = new ArrayList<>(); @@ -375,7 +375,7 @@ public class HtmlEx { private /* static */ void withinParagraph(StringBuilder out, Spanned text, int start, int end) { int next; for (int i = start; i < end; i = next) { - next = text.nextSpanTransition(i, end, CharacterStyle.class); + next = nextSpanTransition(text, i, end, CharacterStyle.class); try { CharacterStyle[] style = getSpans(text, i, next, CharacterStyle.class); @@ -578,7 +578,16 @@ public class HtmlEx { } } - private T[] getSpans(Spanned text, int start, int end, Class type) { + private static int nextSpanTransition(Spanned text, int start, int limit, Class type) { + try { + return text.nextSpanTransition(start, limit, type); + } catch (Throwable ex) { + Log.e(ex); + return limit; + } + } + + private static T[] getSpans(Spanned text, int start, int end, Class type) { try { return text.getSpans(start, end, type); } catch (Throwable ex) {