Prevent crash

This commit is contained in:
M66B 2022-10-27 09:44:12 +02:00
parent 107622992a
commit 21b8ba0a2a
1 changed files with 14 additions and 5 deletions

View File

@ -103,7 +103,7 @@ public class HtmlEx {
int next; int next;
for (int i = 0; i < len; i = 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); ParagraphStyle[] style = getSpans(text, i, next, ParagraphStyle.class);
String elements = " "; String elements = " ";
boolean needDiv = false; boolean needDiv = false;
@ -138,8 +138,8 @@ public class HtmlEx {
int option) { int option) {
int next; int next;
for (int i = start; i < end; i = next) { for (int i = start; i < end; i = next) {
int n1 = text.nextSpanTransition(i, end, QuoteSpan.class); int n1 = nextSpanTransition(text, i, end, QuoteSpan.class);
int n2 = text.nextSpanTransition(i, end, eu.faircode.email.IndentSpan.class); int n2 = nextSpanTransition(text, i, end, eu.faircode.email.IndentSpan.class);
next = Math.min(n1, n2); next = Math.min(n1, n2);
try { try {
List<Object> spans = new ArrayList<>(); List<Object> spans = new ArrayList<>();
@ -375,7 +375,7 @@ public class HtmlEx {
private /* static */ void withinParagraph(StringBuilder out, Spanned text, int start, int end) { private /* static */ void withinParagraph(StringBuilder out, Spanned text, int start, int end) {
int next; int next;
for (int i = start; i < end; i = next) { for (int i = start; i < end; i = next) {
next = text.nextSpanTransition(i, end, CharacterStyle.class); next = nextSpanTransition(text, i, end, CharacterStyle.class);
try { try {
CharacterStyle[] style = getSpans(text, i, next, CharacterStyle.class); CharacterStyle[] style = getSpans(text, i, next, CharacterStyle.class);
@ -578,7 +578,16 @@ public class HtmlEx {
} }
} }
private <T> T[] getSpans(Spanned text, int start, int end, Class<T> 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> T[] getSpans(Spanned text, int start, int end, Class<T> type) {
try { try {
return text.getSpans(start, end, type); return text.getSpans(start, end, type);
} catch (Throwable ex) { } catch (Throwable ex) {