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

IndexOutOfBoundsException caused by BlockQuotesController #19

Closed
korelstar opened this issue Dec 21, 2016 · 11 comments
Closed

IndexOutOfBoundsException caused by BlockQuotesController #19

korelstar opened this issue Dec 21, 2016 · 11 comments
Labels

Comments

@korelstar
Copy link
Contributor

I'm getting a reproducable IndexOutOfBoundsException caused by BlockQuotesController. Way to reproduce:

Type Test into a RxMDEditText. Then press 4 times backspace in order to remove all characters. On removing the third character, the following exception is thrown:

java.lang.IndexOutOfBoundsException: getChars (1 ... 2) ends beyond length 1
    at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1090)
    at android.text.SpannableStringBuilder.getChars(SpannableStringBuilder.java:972)
    at android.text.TextUtils.getChars(TextUtils.java:87)
    at android.text.SpannableStringBuilder.<init>(SpannableStringBuilder.java:65)
    at android.text.SpannableStringBuilder.subSequence(SpannableStringBuilder.java:964)
    at com.yydcdut.rxmarkdown.edit.BlockQuotesController.onTextChanged(BlockQuotesController.java:74)
    at com.yydcdut.rxmarkdown.RxMDEditText.onTextChanged4Controller(RxMDEditText.java:265)
    at com.yydcdut.rxmarkdown.RxMDEditText.access$800(RxMDEditText.java:54)
    at com.yydcdut.rxmarkdown.RxMDEditText$1.onTextChanged(RxMDEditText.java:186)
    at android.widget.TextView.sendOnTextChanged(TextView.java:7991)
    at android.widget.TextView.handleTextChanged(TextView.java:8053)
    at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:10157)
    at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:1033)
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:559)
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:492)
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:491)
    at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:685)
    at android.view.inputmethod.BaseInputConnection.setComposingText(BaseInputConnection.java:445)
    at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:340)
    at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
@korelstar
Copy link
Contributor Author

This bug still occurs in 0.0.8-beta. Do you were able to reproduce it?

@yydcdut
Copy link
Owner

yydcdut commented Feb 28, 2017

Sorry, I will fix it at this weekend.

@yydcdut
Copy link
Owner

yydcdut commented Mar 1, 2017

@korelstar
So, type Test and then, delete t, s, e. When deleting T, app crashed?

@korelstar
Copy link
Contributor Author

Using the example app in this repository:

  1. Change default Text to Test in https://github.com/yydcdut/RxMarkdown/blob/master/app/src/main/java/com/yydcdut/markdowndemo/EditActivity.java#L81
  2. Start example app, chose Edit and Show
  3. Put the cursor to the end of the line (after Test)
  4. Press ⌫ on your virtual keyboard (removes t)
  5. Press ⌫ on your virtual keyboard (removes s)
  6. Press ⌫ on your virtual keyboard (the app crashes)

It is important that no other Text is in the EditText.

@yydcdut
Copy link
Owner

yydcdut commented Mar 1, 2017

It doesn't crash on my phone

@korelstar
Copy link
Contributor Author

That's strange. I've tested with different devices and in the emulator. Always the same.

I will try to investigate further ...

@korelstar
Copy link
Contributor Author

I've installed Android Studio (latest version) on another computer with another OS (Windows instead of Linux) using the default configuration, created an emulator with the default configuration and checked out the master branch of this repository. Then I did the steps shown above (#19 (comment)) and found that the app crashes! Here is the updated Exception (line numbers differ to my first posting, since master has changed).

java.lang.IndexOutOfBoundsException: getChars (1 ... 2) ends beyond length 1
    at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1265)
    at android.text.SpannableStringBuilder.getChars(SpannableStringBuilder.java:1147)
    at android.text.TextUtils.getChars(TextUtils.java:89)
    at android.text.SpannableStringBuilder.<init>(SpannableStringBuilder.java:66)
    at android.text.SpannableStringBuilder.subSequence(SpannableStringBuilder.java:1139)
    at com.yydcdut.rxmarkdown.edit.BlockQuotesController.onTextChanged(BlockQuotesController.java:74)
    at com.yydcdut.rxmarkdown.RxMDEditText.onTextChanged4Controller(RxMDEditText.java:291)
    at com.yydcdut.rxmarkdown.RxMDEditText.access$900(RxMDEditText.java:54)
    at com.yydcdut.rxmarkdown.RxMDEditText$EditTextWatcher.onTextChanged(RxMDEditText.java:212)
    at android.widget.TextView.sendOnTextChanged(TextView.java:8186)
    at android.widget.TextView.handleTextChanged(TextView.java:8248)
    at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:10370)
    at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:1208)
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:578)
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:509)
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:508)
    at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:844)
    at android.view.inputmethod.BaseInputConnection.setComposingText(BaseInputConnection.java:617)
    at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:400)
    at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:91)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

So what's different between us? Is it possible that you try with a fresh installation, too?

@yydcdut
Copy link
Owner

yydcdut commented Mar 1, 2017

It's no reason crashed on method com.yydcdut.rxmarkdown.edit.BlockQuotesController.onTextChanged(CharSequence s, int start, int before, int after) when deleting.
The parameter 'after' is always 0 when deleting, and

if (after == 0) {
        return;
}

@yydcdut
Copy link
Owner

yydcdut commented Mar 1, 2017

OK, I reproduced it.
Delete 3 or 4 chars and add less 3 or 4 char in the same time.

@korelstar
Copy link
Contributor Author

Exactly! Phew, I'm very happy that you were able to reproduce it. 😄

Any ideas how to solve this? I had problems to understand the respective code ...

@yydcdut
Copy link
Owner

yydcdut commented Mar 1, 2017

I will fix it tomorrow~
haha, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants