question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RxTextView.textChanges crashes when one of subscriptions produces an error

See original GitHub issue

Hi Jake and everyone! Thanks for excellent job!

When I use RxTextView.textChanges with several subscriptions and one of them produces an error (which I handle properly) the app crashes.

Here is the simple code:

RxTextView.textChanges(editQuery)
        .skip(1) // we need the error to happen when the user changes the text so skipping initial value
        .concatMap(cs -> Observable.error(new Exception("aaa")))
        .subscribe(Observers.create(o -> {}, e -> Log.e(LOG_TAG, "error" + e)));

RxTextView.textChanges(editQuery)
        .subscribe(s -> Log.e(LOG_TAG, "text: " + s));

When I run my app and type something in my EditText the app crashes:

java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
     at java.util.ArrayList.get(ArrayList.java:308)
     at android.widget.TextView.sendOnTextChanged(TextView.java:7679)
     at android.widget.TextView.handleTextChanged(TextView.java:7739)
     at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:9472)
     at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:964)
     at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:515)
     at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:454)
     at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:33)
     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:135)
     at android.app.ActivityThread.main(ActivityThread.java:5257)
     at java.lang.reflect.Method.invoke(Native Method)
     at java.lang.reflect.Method.invoke(java.lang.reflect.Method.java:372)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

And it happens because when user types something, the first subscription throws an Exception and then TextView.removeTextChangedListener is called in TextViewTextOnSubscribe.java:39 (because of unsubscribe after error). But the TextView is still iterating over it’s watchers in the TextView.sendOnTextChanged method!

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
micdmcommented, Jun 24, 2016

Have spent several hours to locate that bug. The easiest example to reproduce (place it to Activity.onCreate for example):

TextView view = new TextView(this);
RxTextView.textChanges(view).skip(1).take(1).subscribe();
RxTextView.textChanges(view).skip(1).subscribe();
view.setText("hello");

Workaround may be (as @dlew mentioned):

Observable<CharSequence> text = RxTextView.textChanges(view).skip(1).share();
text.take(1).subscribe();
text.subscribe();
view.setText("hello");
0reactions
JakeWhartoncommented, Jun 24, 2016

Great! I’ll take care of it.

On Fri, Jun 24, 2016, 1:40 AM Mikhail Demerzov notifications@github.com wrote:

https://code.google.com/p/android/issues/detail?id=190399 is about that. Seems pretty dead.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JakeWharton/RxBinding/issues/192#issuecomment-228262368, or mute the thread https://github.com/notifications/unsubscribe/AAEEEfZm7o_dxSM7r6sUOQ2MeYTRshM6ks5qO226gaJpZM4Gg_co .

Read more comments on GitHub >

github_iconTop Results From Across the Web

NotRxAndroid - Bountysource
When I use RxTextView.textChanges with several subscriptions and one of them produces an error (which I handle properly) the app crashes.
Read more >
RxBinding TextChanges won't continue emitting text changes
Trying to figure out why RxTextView.textChanges only emits the initial value. My understanding is that it should emit all new text changes to ......
Read more >
Exploring RxJava in Android
RxBinding has a built in method for doing this, RxTextView.textChanges() . It takes a EditText and returns an Observable emmitting a ...
Read more >
Error handling in RxJava
Let's say you have an observable that can produce an exception. ... Even worse is that there wouldn't be any crash in the...
Read more >
RxJava for Android Developers
RxTextView.textChanges(textInput);. 1. textObservable .subscribe(this::updateSearchResults); 2. 1 Create an observable based on the text input change.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found