Prevent crash

pull/209/head
M66B 2 years ago
parent 107622992a
commit 21b8ba0a2a

@ -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<Object> 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> 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 {
return text.getSpans(start, end, type);
} catch (Throwable ex) {

Loading…
Cancel
Save