Skip to content

RxJavaPlugins.reset() does not reset Observable.hook #4006

Closed
@DariusL

Description

@DariusL

I tried using the RxJavaObservableExecutionHook and noticed that once used, it cannot be changed. It seems that Observable holds a static reference to this hook and uses whatever was set when the class was created. Calling reset() has no effect on Observable.

import org.junit.Test;

import rx.Observable;
import rx.plugins.RxJavaObservableExecutionHook;
import rx.plugins.RxJavaPlugins;

import static org.junit.Assert.assertTrue;

public class HookTest {

    @Test
    public void testChangeHooks() {
        Hook first = new Hook();
        RxJavaPlugins.getInstance().registerObservableExecutionHook(first);

        Observable.just(null).subscribe();

        assertTrue(first.invoked);

        RxJavaPlugins.getInstance().reset();
        Hook second = new Hook();
        RxJavaPlugins.getInstance().registerObservableExecutionHook(second);

        Observable.just(null).subscribe();

        assertTrue(second.invoked);
    }

    static class Hook extends RxJavaObservableExecutionHook {
        boolean invoked = false;

        @Override
        public <T> Observable.OnSubscribe<T> onSubscribeStart(Observable<? extends T> observableInstance, Observable.OnSubscribe<T> onSubscribe) {
            invoked = true;
            return super.onSubscribeStart(observableInstance, onSubscribe);
        }
    }
}

The second assert fails. I'm using 1.1.5.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions