StompProtocolAndroid: OnErrorNotImplementedException in StompClient.java

First off, thank you to everyone who works on this awesome project it really works well and is extremely useful.

I may have found a bug. Hopefully this has not been posted about and answered already, I tried to read all of the existing Issues and didn’t see this exact issue.

First, some background: I have seen the OnErrorNotImplementedException like other users:

io.reactivex.exceptions.OnErrorNotImplementedException: The exception was not handled due to missing onError handler in the subscribe() method call. Further reading: https://github.com/ReactiveX/RxJava/wiki/Error-Handling | java.util.NoSuchElementException

…and after reading through the other issues posted and Stack Overflow I have fixed it by adding an error handler to my code that calls subscribe(), like so:

        // begin topic subscription for user data
        stompClient.topic(TOPIC_NAME_HERE)
            .doOnError(throwable -> {
                // log the error and tell the service to resubscribe
            })
            .subscribeOn(Schedulers.io())
            .subscribe(new Subscriber<StompMessage>() {
                @Override
                public void onSubscribe(Subscription subscription) {
                }

                @Override
                public void onNext(StompMessage topicMessage) {
                    // handle the incoming message
                }

                @Override
                public void onError(Throwable error) {
                    Log.e(TAG, "Error on user data topic", error);
                    resubscribe = true;
                }

                @Override
                public void onComplete() {
                }
            });

This made the crashes extremely rare. With the help of the debugger I found that crashes would still happen occasionally when using the StompClient to use heartbeat messages inside the StompClient’s connect method. In that method the subscribe call is made but no error handler is specified. When I initially connect the StompClient and setup heartbeating (via stompClient.withClientHeartbeat(1000).withServerHeartbeat(1000);) I see the error occur after I call stompClient.disconnect(). I think this is because there is an error that is not handled.

I might have totally missed something… If this is a legit issue would be happy to add the error handlers to the StompClient connect() method code and create a PR if it helps.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 19 (3 by maintainers)

Most upvoted comments

It works after I added this line.

    stompClient.setPathMatcher(ActivePathMatcher());

I had to make some changes to the library locally

:trollface:

If you’re starting a new project, don’t use this legacy library. Use tinder/scarlet.