Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown crash repro #442

Closed
wants to merge 3 commits into from
Closed

Conversation

Wavesonics
Copy link
Contributor

@Wavesonics Wavesonics commented Dec 7, 2024

This is not meant to be merged, it is a branch based off the head of main right now, which reproduces a crash.

The steps to repro:

  1. Set a RichTextEditor value to a long string of markdown
  2. Click into the editor
  3. Modify the content, either add or delete a character
  4. Observe the crash
crash-repro.mp4

Stack Trace:

Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: Range [8487, 8494) out of bounds for length 8487
	at java.base/jdk.internal.util.Preconditions$1.apply(Unknown Source)
	at java.base/jdk.internal.util.Preconditions$1.apply(Unknown Source)
	at java.base/jdk.internal.util.Preconditions$4.apply(Unknown Source)
	at java.base/jdk.internal.util.Preconditions$4.apply(Unknown Source)
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Unknown Source)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckFromToIndex(Unknown Source)
	at java.base/jdk.internal.util.Preconditions.checkFromToIndex(Unknown Source)
	at java.base/java.lang.String.checkBoundsBeginEnd(Unknown Source)
	at java.base/java.lang.String.substring(Unknown Source)
	at com.mohamedrejeb.richeditor.utils.AnnotatedStringExtKt.append-UJKp_GQ(AnnotatedStringExt.kt:119)
	at com.mohamedrejeb.richeditor.utils.AnnotatedStringExtKt.appendRichSpan-XtCa3Zc(AnnotatedStringExt.kt:58)
	at com.mohamedrejeb.richeditor.utils.AnnotatedStringExtKt.appendRichSpan-XtCa3Zc$default(AnnotatedStringExt.kt:43)
	at com.mohamedrejeb.richeditor.utils.AnnotatedStringExtKt.append-UJKp_GQ(AnnotatedStringExt.kt:30)
	at com.mohamedrejeb.richeditor.model.RichTextState.updateAnnotatedString$richeditor_compose(RichTextState.kt:1216)
	at com.mohamedrejeb.richeditor.model.RichTextState.updateTextFieldValue(RichTextState.kt:1163)
	at com.mohamedrejeb.richeditor.model.RichTextState.updateTextFieldValue$default(RichTextState.kt:1147)
	at com.mohamedrejeb.richeditor.model.RichTextState.onTextFieldValueChange$richeditor_compose(RichTextState.kt:1139)
	at com.mohamedrejeb.richeditor.ui.BasicRichTextEditorKt$BasicRichTextEditor$8.invoke$lambda$1$lambda$0(BasicRichTextEditor.kt:242)
	at androidx.compose.foundation.text.BasicTextFieldKt$BasicTextField$11$1.invoke(BasicTextField.kt:771)
	at androidx.compose.foundation.text.BasicTextFieldKt$BasicTextField$11$1.invoke(BasicTextField.kt:769)
	at androidx.compose.foundation.text.LegacyTextFieldState$onValueChange$1.invoke(CoreTextField.kt:1006)
	at androidx.compose.foundation.text.LegacyTextFieldState$onValueChange$1.invoke(CoreTextField.kt:999)
	at androidx.compose.foundation.text.TextFieldKeyInput.apply(TextFieldKeyInput.kt:71)
	at androidx.compose.foundation.text.TextFieldKeyInput.apply(TextFieldKeyInput.kt:75)
	at androidx.compose.foundation.text.TextFieldKeyInput.process-ZmokQxo(TextFieldKeyInput.kt:91)
	at androidx.compose.foundation.text.TextFieldKeyInputKt$textFieldKeyInput$2$1$1.invoke-ZmokQxo(TextFieldKeyInput.kt:261)
	at androidx.compose.foundation.text.TextFieldKeyInputKt$textFieldKeyInput$2$1$1.invoke(TextFieldKeyInput.kt:261)
	at androidx.compose.ui.input.key.KeyInputNode.onKeyEvent-ZmokQxo(KeyInputModifier.kt:80)
	at androidx.compose.ui.focus.FocusOwnerImpl.dispatchKeyEvent-YhN2O0w(FocusOwnerImpl.kt:275)
	at androidx.compose.ui.focus.FocusOwner.dispatchKeyEvent-YhN2O0w$default(FocusOwner.kt:142)
	at androidx.compose.ui.node.RootNodeOwner.onKeyEvent-ZmokQxo(RootNodeOwner.skiko.kt:260)
	at androidx.compose.ui.scene.CanvasLayersComposeSceneImpl.processKeyEvent-ZmokQxo(CanvasLayersComposeScene.skiko.kt:243)
	at androidx.compose.ui.scene.BaseComposeScene$inputHandler$3.invoke-ZmokQxo(BaseComposeScene.skiko.kt:64)
	at androidx.compose.ui.scene.BaseComposeScene$inputHandler$3.invoke(BaseComposeScene.skiko.kt:64)
	at androidx.compose.ui.scene.ComposeSceneInputHandler.onKeyEvent-ZmokQxo(ComposeSceneInputHandler.skiko.kt:129)
	at androidx.compose.ui.scene.BaseComposeScene.sendKeyEvent-ZmokQxo(BaseComposeScene.skiko.kt:245)
	at androidx.compose.ui.scene.ComposeSceneMediator.onKeyEvent(ComposeSceneMediator.desktop.kt:464)
	at androidx.compose.ui.scene.ComposeSceneMediator.access$onKeyEvent(ComposeSceneMediator.desktop.kt:113)
	at androidx.compose.ui.scene.ComposeSceneMediator$keyListener$1.keyTyped(ComposeSceneMediator.desktop.kt:268)
	at java.desktop/java.awt.Component.processKeyEvent(Unknown Source)
	at java.desktop/java.awt.Component.processEvent(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)

@Wavesonics
Copy link
Contributor Author

Wavesonics commented Dec 7, 2024

I think it has to do with malformed markdown. I tried a lorem ipsum string of similar length going through the setMarkdown method and it didn't crash.

It looks to be related to mismatched code span backticks `? Or maybe just code spans that cross paragraph boundaries? I'm not entirely sure yet.

Another oddity in the markdown parser:

        outlinedRichTextState.setMarkdown(
"""one and two

            wdw""".trimIndent())
    }

The leading four spaces on the 3rd line here cause it to not be parsed into the final content, which I think is a separate bug:
#443

Under four spaces is parsed just fine, but four or more leading spaces and the line is dropped from the output.

If I delete what is now the last paragraph, it stops crashing.
@Wavesonics
Copy link
Contributor Author

Added a test that repros #443

@MohamedRejeb
Copy link
Owner

Thanks for the repro. The main issue was with having a code span split between two lines, it should be working fine now

@Wavesonics Wavesonics closed this Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants