RxTextView.textChanges crashes when one of subscriptions produces an error
See original GitHub issueHi 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:
- Created 8 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Have spent several hours to locate that bug. The easiest example to reproduce (place it to
Activity.onCreate
for example):Workaround may be (as @dlew mentioned):
Great! I’ll take care of it.
On Fri, Jun 24, 2016, 1:40 AM Mikhail Demerzov notifications@github.com wrote: