StrictSubscriber extends AtomicInteger implements FlowableSubscriber<T>, Subscription { @Override public void onSubscribe(Subscription s) { if (once.compareAndSet(false, true)) { actual.onSubscribe(this); SubscriptionHelper.deferredSetOnce(this.s, requested, s); } else { s.cancel(); cancel(); onError(new IllegalStateException("§2.12 violated: onSubscribe must be called at most once")); } } StrictSubscriber(Subscriber<? super T> actual); @Override void request(long n); @Override void cancel(); @Override void onSubscribe(Subscription s); @Override void onNext(T t); @Override void onError(Throwable t); @Override void onComplete();  }
@Test public void doubleOnSubscribe() { TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); SubscriberWrapper<Integer> wrapper = new SubscriberWrapper<Integer>(ts); new Flowable<Integer>() { @Override protected void subscribeActual(Subscriber<? super Integer> s) { BooleanSubscription b1 = new BooleanSubscription(); s.onSubscribe(b1); BooleanSubscription b2 = new BooleanSubscription(); s.onSubscribe(b2); assertTrue(b1.isCancelled()); assertTrue(b2.isCancelled()); } }.subscribe(wrapper); ts.assertFailure(IllegalStateException.class); assertTrue(ts.errors().toString(), ts.errors().get(0).getMessage().contains("2.12")); }