vanniktech / Emoji

A library to add Emoji support to your Android / iOS / JVM Application
Apache License 2.0
1.54k stars 292 forks source link

Crash when replace one emoticon with big text #140

Closed igor-alyoshin closed 7 years ago

igor-alyoshin commented 7 years ago

versions = 0.4.0-0.5.0 (may be lower) devices = samsung note 3 (may be any) versions = 5.1 (may be any)

1.print more than one emoticons (for example two). 2.select first (long tap). 3.paste text below 4.result: crash 5.try again 6.select second emoticon 7.paste text below 8.result: inserted unknown data (emoticons)

inserted text: "Think about where to screw the plug.

stacktrace 06-15 15:38:51.570 28046-28046/com.vanniktech.emoji.sample E/AndroidRuntime: FATAL EXCEPTION: main Process: com.vanniktech.emoji.sample, PID: 28046 java.lang.IndexOutOfBoundsException: getChars (365 ... 37) has end before start at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1015) at android.text.SpannableStringBuilder.getChars(SpannableStringBuilder.java:919) at android.text.TextUtils.getChars(TextUtils.java:85) at android.text.MeasuredText.setPara(MeasuredText.java:109) at android.text.StaticLayout.generate(StaticLayout.java:508) at android.text.DynamicLayout.reflow(DynamicLayout.java:285) at android.text.DynamicLayout.access$000(DynamicLayout.java:36) at android.text.DynamicLayout$ChangeWatcher.reflow(DynamicLayout.java:639) at android.text.DynamicLayout$ChangeWatcher.onSpanChanged(DynamicLayout.java:668) at android.text.SpannableStringBuilder.sendSpanChanged(SpannableStringBuilder.java:1005) at android.text.SpannableStringBuilder.sendToSpanWatchers(SpannableStringBuilder.java:590) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:523) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:456) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:33) at android.widget.TextView.paste(TextView.java:10820) at android.widget.TextView.onTextContextMenuItem(TextView.java:10238) at android.widget.Editor$SelectionActionModeCallback.onActionItemClicked(Editor.java:3252) at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onActionItemClicked(PhoneWindow.java:3522) at android.support.v7.view.SupportActionModeWrapper$CallbackWrapper.onActionItemClicked(SupportActionModeWrapper.java:173) at android.support.v7.app.AppCompatDelegateImplV9$ActionModeCallbackWrapperV9.onActionItemClicked(AppCompatDelegateImplV9.java:1794) at android.support.v7.app.WindowDecorActionBar$ActionModeImpl.onMenuItemSelected(WindowDecorActionBar.java:1101) at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822) at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:156) at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:969) at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:959) at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:623) at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:154) at android.view.View.performClick(View.java:5184) at android.view.View$PerformClick.run(View.java:20893) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5938) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

vanniktech commented 7 years ago

Interesting. Can you provide the String that caused the crash? And if possible trying to narrow it down?

vanniktech commented 7 years ago

Also you can try 0.5.0-SNAPSHOT

igor-alyoshin commented 7 years ago

Could not find com.vanniktech:emoji-ios:0.5.0-SNAPSHOT. Could not find com.vanniktech:emoji:0.5.0-SNAPSHOT. 0.5.0 I checked. Same error.

One of the key conditions is a big text. String:

"Think about where to screw the plug. The success for you is to build an excellent low-level unit-testing framework that uses everything and that runs on the test server millions of times a day. When you are asked if the product is ready for release, you can simply answer: "All tests have passed." You are more suited to the role of a testing engineer, if you: You can take the existing code, find errors in it and immediately understand where there may be failures, but you are not particularly attracted by the idea of writing code"

vanniktech commented 7 years ago

You need to add the maven snapshort url.

Is it on purpose that there are no Emojis in the text or are there any hidden unicode characters?

igor-alyoshin commented 7 years ago

I only want replace one emoji with some text. For example string: "testing framework that uses everything and that runs on the test server millions of time" It's a standart visible characters

rubengees commented 7 years ago

This is an Android Bug. We may try to include the workaround in the SO answers.

igor-alyoshin commented 7 years ago

Yes. But it works if edittext not contains emoticons. My workaround https://gist.github.com/igor-alyoshin/4b9d07c06cf6a4a6256beda649871613

vanniktech commented 7 years ago

So the workaround is to use editor.setSelection(editor.getText().length(), editor.getText().length());?

igor-alyoshin commented 7 years ago

No. If you replace the middle emoticon (3+ emoticons in EditText) cursor moved to last position

vanniktech commented 7 years ago

I'm closing this issue due to inactivity. If you have any further input on the issue, don't hesitate to reopen this issue or post a new one.