private ThreadSafeLazyLoadedIvoryTower() { // protect against instantiation via reflection if (instance == null) { instance = this; } else { throw new IllegalStateException("Already initialized."); } }
/** * private constructor to prevent client from instantiating. */ private ThreadSafeDoubleCheckLocking() { // to prevent instantiating by Reflection call if (instance != null) { throw new IllegalStateException("Already initialized."); } }
@Override public void onError(Throwable throwable) { throw new IllegalStateException("Should not occur"); } }
/** Utility class. */ private Exceptions() { throw new IllegalStateException("No instances!"); } /**
/** Helper class, no instances. */ private RxJavaPlugins() { throw new IllegalStateException("No instances!"); } }
/** * Sets the specific hook function. * @param handler the hook function to set, null allowed, but the function may not return null */ public static void setInitIoSchedulerHandler(@Nullable Function<? super Callable<Scheduler>, ? extends Scheduler> handler) { if (lockdown) { throw new IllegalStateException("Plugins can't be changed anymore"); } onInitIoHandler = handler; }
/** * Sets the specific hook function. * @param handler the hook function to set, null allowed, but the function may not return null */ public static void setInitNewThreadSchedulerHandler(@Nullable Function<? super Callable<Scheduler>, ? extends Scheduler> handler) { if (lockdown) { throw new IllegalStateException("Plugins can't be changed anymore"); } onInitNewThreadHandler = handler; }
/** * Sets the specific hook function. * @param handler the hook function to set, null allowed, but the function may not return null */ public static void setInitSingleSchedulerHandler(@Nullable Function<? super Callable<Scheduler>, ? extends Scheduler> handler) { if (lockdown) { throw new IllegalStateException("Plugins can't be changed anymore"); } onInitSingleHandler = handler; }
/** * Sets the specific hook function. * @param onObservableSubscribe the hook function to set, null allowed */ @SuppressWarnings("rawtypes") public static void setOnObservableSubscribe( @Nullable BiFunction<? super Observable, ? super Observer, ? extends Observer> onObservableSubscribe) { if (lockdown) { throw new IllegalStateException("Plugins can't be changed anymore"); } RxJavaPlugins.onObservableSubscribe = onObservableSubscribe; }
/** * Sets the specific hook function. * @param handler the hook function to set, null allowed */ public static void setErrorHandler(@Nullable Consumer<? super Throwable> handler) { if (lockdown) { throw new IllegalStateException("Plugins can't be changed anymore"); } errorHandler = handler; }
/** * Sets the specific hook function. * @param onFlowableSubscribe the hook function to set, null allowed */ @SuppressWarnings("rawtypes") public static void setOnFlowableSubscribe(@Nullable BiFunction<? super Flowable, ? super Subscriber, ? extends Subscriber> onFlowableSubscribe) { if (lockdown) { throw new IllegalStateException("Plugins can't be changed anymore"); } RxJavaPlugins.onFlowableSubscribe = onFlowableSubscribe; }
/** * Sets the specific hook function. * @param onSingleAssembly the hook function to set, null allowed */ @SuppressWarnings("rawtypes") public static void setOnSingleAssembly(@Nullable Function<? super Single, ? extends Single> onSingleAssembly) { if (lockdown) { throw new IllegalStateException("Plugins can't be changed anymore"); } RxJavaPlugins.onSingleAssembly = onSingleAssembly; }
/** * Sets the specific hook function. * @param onSingleSubscribe the hook function to set, null allowed */ @SuppressWarnings("rawtypes") public static void setOnSingleSubscribe(@Nullable BiFunction<? super Single, ? super SingleObserver, ? extends SingleObserver> onSingleSubscribe) { if (lockdown) { throw new IllegalStateException("Plugins can't be changed anymore"); } RxJavaPlugins.onSingleSubscribe = onSingleSubscribe; }
@Override public void run() { throw new IllegalStateException(); } });
@Override public Integer apply(Integer a, Integer b) throws Exception { throw new IllegalStateException(); } })
/** * Sets the specific hook function. * @param handler the hook function to set, null allowed, but the function may not return null */ public static void setInitComputationSchedulerHandler(@Nullable Function<? super Callable<Scheduler>, ? extends Scheduler> handler) { if (lockdown) { throw new IllegalStateException("Plugins can't be changed anymore"); } onInitComputationHandler = handler; }
/** * Sets the specific hook function. * @param handler the hook function to set, null allowed */ public static void setIoSchedulerHandler(@Nullable Function<? super Scheduler, ? extends Scheduler> handler) { if (lockdown) { throw new IllegalStateException("Plugins can't be changed anymore"); } onIoHandler = handler; }
/** * Sets the specific hook function. * @param onMaybeSubscribe the hook function to set, null allowed */ @SuppressWarnings("rawtypes") public static void setOnMaybeSubscribe(@Nullable BiFunction<? super Maybe, MaybeObserver, ? extends MaybeObserver> onMaybeSubscribe) { if (lockdown) { throw new IllegalStateException("Plugins can't be changed anymore"); } RxJavaPlugins.onMaybeSubscribe = onMaybeSubscribe; }
@Override public void onSubscribe(Subscription s) { if (once.compareAndSet(false, true)) { downstream.onSubscribe(this); SubscriptionHelper.deferredSetOnce(this.upstream, requested, s); } else { s.cancel(); cancel(); onError(new IllegalStateException("§2.12 violated: onSubscribe must be called at most once")); } }
/** * We expect IllegalStateException to pass thru map. */ @Test(expected = IllegalStateException.class) public void testErrorPassesThruMap2() { Observable.error(new IllegalStateException()).map(new Function<Object, Object>() { @Override public Object apply(Object i) { return i; } }).blockingSingle(); }