From 71af1e59094820dcacb32f45cdf8afba98d7f26c Mon Sep 17 00:00:00 2001 From: Marten Gajda Date: Sun, 21 Mar 2021 15:16:51 +0100 Subject: [PATCH] Fix potential StringIndexOutOfBoundsException, fixes #1020 (#1023) At present it's still unclear under which condition this issue was triggered. It should no longer crash though, the UI might just behave a bit strangely instead. --- .../java/org/dmfs/tasks/widget/DescriptionFieldView.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/opentasks/src/main/java/org/dmfs/tasks/widget/DescriptionFieldView.java b/opentasks/src/main/java/org/dmfs/tasks/widget/DescriptionFieldView.java index 93e41f79..a1eea171 100644 --- a/opentasks/src/main/java/org/dmfs/tasks/widget/DescriptionFieldView.java +++ b/opentasks/src/main/java/org/dmfs/tasks/widget/DescriptionFieldView.java @@ -332,9 +332,10 @@ private void bindItemView(final View itemView, final DescriptionItem item) return true; } // split current - int sel = text.getSelectionStart(); - String newText = text.getText().toString().substring(sel); - item.text = text.getText().toString().substring(0, sel); + String current = text.getText().toString(); + int sel = Math.max(0, Math.min(current.length(), text.getSelectionStart())); + String newText = current.substring(sel); + item.text = current.substring(0, sel); text.setText(item.text); text.clearFocus(); // create new item with new test