Rosemoe/sora-editor

Crash due to editor : java.lang.IllegalArgumentException: Not a valid Unicode code point: 0x800002C6

m-anshuman2166 opened this issue · 1 comments

StackTrace

Fatal Exception: java.lang.IllegalArgumentException: Not a valid Unicode code point: 0x800002C6
       at java.lang.Character.toChars(Character.java:9280)
       at io.github.rosemoe.sora.widget.EditorKeyEventHandler.handlePrintingKey(EditorKeyEventHandler.java:410)
       at io.github.rosemoe.sora.widget.EditorKeyEventHandler.handleKeyEvent(EditorKeyEventHandler.java:396)
       at io.github.rosemoe.sora.widget.EditorKeyEventHandler.onKeyDown(EditorKeyEventHandler.java:158)
       at io.github.rosemoe.sora.widget.CodeEditor.onKeyDown(CodeEditor.java:4608)
       at android.view.KeyEvent.dispatch(KeyEvent.java:3498)
       at android.view.View.dispatchKeyEvent(View.java:16061)
       at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1988)
       at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1988)
       at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1988)
       at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1988)
       at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1988)
       at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1988)
       at com.android.internal.policy.DecorView.superDispatchKeyEvent(DecorView.java:774)
       at com.android.internal.policy.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1957)
       at android.app.Activity.dispatchKeyEvent(Activity.java:4483)
       at androidx.core.app.ComponentActivity.superDispatchKeyEvent(ComponentActivity.java:120)
       at androidx.core.view.KeyEventDispatcher.dispatchKeyEvent(KeyEventDispatcher.java:85)
       at androidx.core.app.ComponentActivity.dispatchKeyEvent(ComponentActivity.java:138)
       at androidx.appcompat.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:604)
       at androidx.appcompat.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:60)
       at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.dispatchKeyEvent(AppCompatDelegateImpl.java:3413)
       at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:688)
       at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:8412)
       at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:8272)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:7605)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:7662)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:7628)
       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:7831)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:7636)
       at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:7888)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:7609)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:7662)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:7628)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:7636)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:7609)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:7662)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:7628)
       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:7864)
       at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:8106)
       at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:4578)
       at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:4012)
       at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:4003)
       at android.view.inputmethod.InputMethodManager.-$$Nest$mfinishedInputEvent()
       at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:4555)
       at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:154)
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:335)
       at android.os.Looper.loopOnce(Looper.java:187)
       at android.os.Looper.loop(Looper.java:319)
       at android.app.ActivityThread.main(ActivityThread.java:8913)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

Occurrences observed on :

  • Android 14, Galaxy Tab S6 Lite

This crash report has been collected using Firebase Crashlytics, I can't reproduce this error on my own device.

Library Versions

implementation("io.github.Rosemoe.sora-editor:editor:0.22.2")
implementation("io.github.Rosemoe.sora-editor:language-textmate:0.22.2")

It's an unresolved bug in the editor, and it happens due to the reason below.

The editor inserts the unicode char from platform API KeyEvent#getUnicodeChar directly.
According to the bad code point value and javadoc of getUnicodeChar, 0x800002C6 is a masked code point which indicates this key needs special treatment to actually produce a character. And the masked code point is invalid, so the exception is thrown. After removing the mask, the code point represents U+02C6, which is a modifier letter for circumflex accent.

From Android docs:

If the return value has bit KeyCharacterMap.COMBINING_ACCENT set, the key is a "dead key" that should be combined with another to actually produce a character -- see KeyCharacterMap.getDeadChar -- after masking with KeyCharacterMap.COMBINING_ACCENT_MASK.

From Android source code:

public static final int COMBINING_ACCENT = 0x80000000

Before version 0.23.2, the editor transforms the result getUnicodeChar directly into a char array by Character#toChars and insert it.
In version 0.23.2 the editor avoids to insert private-use Unicode characters for Android framework, but still, does not handle the masked code points.

I'll fix the bug soon.