sora-editor icon indicating copy to clipboard operation
sora-editor copied to clipboard

[Bug]: StringIndexOutOfBoundsException when deleting

Open Raival-e opened this issue 4 months ago • 2 comments

I wanted to delete a big chunk of code, so I pressed delete button in my keyboard continuously, it was deleting fine until suddenly crashed and showed this error.

version: v0.23.6

java.lang.StringIndexOutOfBoundsException: length=1; index=1
	at java.lang.String.charAt(Native Method)
	at io.github.rosemoe.sora.text.ContentLine.charAt(ContentLine.java:270)
	at io.github.rosemoe.sora.text.Content.charAt(Content.java:184)
	at io.github.rosemoe.sora.lang.brackets.OnlineBracketsMatcher.tryComputePaired(OnlineBracketsMatcher.java:84)
	at io.github.rosemoe.sora.lang.brackets.OnlineBracketsMatcher.getPairedBracketAt(OnlineBracketsMatcher.java:104)
	at io.github.rosemoe.sora.widget.EditorStyleDelegate.lambda$postUpdateBracketPair$1(EditorStyleDelegate.java:68)
	at io.github.rosemoe.sora.widget.EditorStyleDelegate.$r8$lambda$QQeojjBRf12hp1fIns_TIbVd5yo(Unknown Source:0)
	at io.github.rosemoe.sora.widget.EditorStyleDelegate$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
	at io.github.rosemoe.sora.widget.EditorStyleDelegate.runOnUiThread(EditorStyleDelegate.java:90)
	at io.github.rosemoe.sora.widget.EditorStyleDelegate.postUpdateBracketPair(EditorStyleDelegate.java:64)
	at io.github.rosemoe.sora.widget.EditorStyleDelegate.lambda$new$0(EditorStyleDelegate.java:52)
	at io.github.rosemoe.sora.widget.EditorStyleDelegate.$r8$lambda$-A4iK_dhq3uJ7UyT1XbqrvhOAfc(Unknown Source:0)
	at io.github.rosemoe.sora.widget.EditorStyleDelegate$$ExternalSyntheticLambda1.onReceive(D8$$SyntheticClass:0)
	at io.github.rosemoe.sora.event.EventManager.dispatchEvent(EventManager.java:242)
	at io.github.rosemoe.sora.widget.CodeEditor.dispatchEvent(CodeEditor.java:3919)
	at io.github.rosemoe.sora.widget.CodeEditor.onSelectionChanged(CodeEditor.java:4447)
	at io.github.rosemoe.sora.widget.CodeEditor.afterDelete(CodeEditor.java:5077)
	at io.github.rosemoe.sora.text.Content.dispatchAfterDelete(Content.java:1038)
	at io.github.rosemoe.sora.text.Content.deleteInternal(Content.java:544)
	at io.github.rosemoe.sora.text.Content.delete(Content.java:468)
	at io.github.rosemoe.sora.widget.CodeEditor.deleteText(CodeEditor.java:1862)
	at io.github.rosemoe.sora.widget.EditorKeyEventHandler.handleKeyEvent(EditorKeyEventHandler.java:193)
	at io.github.rosemoe.sora.widget.EditorKeyEventHandler.onKeyDown(EditorKeyEventHandler.java:151)
	at io.github.rosemoe.sora.widget.CodeEditor.onKeyDown(CodeEditor.java:4691)
	at android.view.KeyEvent.dispatch(KeyEvent.java:3664)
	at android.view.View.dispatchKeyEvent(View.java:14927)
	at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1991)
...

Raival-e avatar Sep 03 '25 15:09 Raival-e

Could you please provide the file you are editing (before deleting) and an approximate selection position where you started presssing the delete button? This will help us to analyze the problem.

Thanks a lot in advance!

Rosemoe avatar Sep 03 '25 17:09 Rosemoe

I'd love to, but unfortunately I don't really have the exact code I was editing, because the file hasn't been saved when the crash happened.

I tried to reproduce the crash multiple times before opening this issue, however I wasn't able to, so I thought the least I can do is to share the logs.

The code was long (probably over 500 lines), I wasn't editing the beginning or the end of the code, it was somewhat in the middle, the part I was deleting was mainly empty lines (with some } and ,). I also believe that I stopped deleting for a bit to make sure that I didn't exceed the part I wanted to delete, then I continued and then it crashed (not sure though, everything happened so quickly lol).

I actually have a similar issue a while ago, but I also didn't have a clear context on how exactly it happened as it seemed very random and obscure. I don't remember exactly if it happened while deleting or not.

Raival-e avatar Sep 03 '25 18:09 Raival-e