Skip to content

Commit 08b5589

Browse files
committed
Nono null checks
1 parent c4ee248 commit 08b5589

File tree

2 files changed

+144
-2
lines changed

2 files changed

+144
-2
lines changed

src/main/java/hu/akarnokd/rxjava2/basetypes/Nono.java

+73-2
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ public static <R> Nono using(Callable<R> resourceSupplier, Function<? super R, ?
253253

254254
public static <R> Nono using(Callable<R> resourceSupplier, Function<? super R, ? extends Nono> sourceSupplier,
255255
Consumer<? super R> disposer, boolean eager) {
256+
ObjectHelper.requireNonNull(resourceSupplier, "resourceSupplier is null");
257+
ObjectHelper.requireNonNull(sourceSupplier, "sourceSupplier is null");
258+
ObjectHelper.requireNonNull(disposer, "disposer is null");
256259
// TODO implement
257260
throw new UnsupportedOperationException();
258261
}
@@ -290,11 +293,14 @@ public static Nono fromObservable(ObservableSource<?> source) {
290293
// -----------------------------------------------------------
291294

292295
public final <T> Flowable<T> andThen(Publisher<? extends T> other) {
296+
ObjectHelper.requireNonNull(other, "other is null");
293297
// TODO implement
294298
throw new UnsupportedOperationException();
295299
}
296300

297301
public final Nono andThen(Nono other) {
302+
ObjectHelper.requireNonNull(other, "other is null");
303+
// TODO implement
298304
throw new UnsupportedOperationException();
299305
}
300306

@@ -305,10 +311,13 @@ public final Nono delay(long delay, TimeUnit unit) {
305311

306312
@SchedulerSupport(SchedulerSupport.CUSTOM)
307313
public final Nono delay(long delay, TimeUnit unit, Scheduler scheduler) {
314+
ObjectHelper.requireNonNull(unit, "unit is null");
315+
ObjectHelper.requireNonNull(scheduler, "scheduler is null");
308316
return onAssembly(new NonoDelay(this, delay, unit, scheduler));
309317
}
310318

311319
public final Nono delaySubscription(Publisher<?> other) {
320+
ObjectHelper.requireNonNull(other, "other is null");
312321
// TODO implement
313322
throw new UnsupportedOperationException();
314323
}
@@ -330,11 +339,16 @@ public final Nono timeout(long delay, TimeUnit unit, Nono fallback) {
330339
}
331340

332341
public final Nono timeout(long delay, TimeUnit unit, Scheduler scheduler) {
342+
ObjectHelper.requireNonNull(unit, "unit is null");
343+
ObjectHelper.requireNonNull(scheduler, "scheduler is null");
333344
// TODO implement
334345
throw new UnsupportedOperationException();
335346
}
336347

337348
public final Nono timeout(long delay, TimeUnit unit, Scheduler scheduler, Nono fallback) {
349+
ObjectHelper.requireNonNull(unit, "unit is null");
350+
ObjectHelper.requireNonNull(scheduler, "scheduler is null");
351+
ObjectHelper.requireNonNull(fallback, "fallback is null");
338352
// TODO implement
339353
throw new UnsupportedOperationException();
340354
}
@@ -344,17 +358,20 @@ public final Nono onErrorComplete() {
344358
}
345359

346360
public final Nono onErrorResumeNext(Function<? super Throwable, ? extends Nono> errorHandler) {
361+
ObjectHelper.requireNonNull(errorHandler, "errorHandler is null");
347362
// TODO implement
348363
throw new UnsupportedOperationException();
349364
}
350365

351366
public final Nono mapError(Function<? super Throwable, ? extends Throwable> mapper) {
352-
// TODO implement
353-
throw new UnsupportedOperationException();
367+
ObjectHelper.requireNonNull(mapper, "mapper is null");
368+
return onAssembly(new NonoMapError(this, mapper));
354369
}
355370

356371
public final <T> Flowable<T> flatMap(Function<? super Throwable, ? extends Publisher<? extends T>> onErrorMapper,
357372
Callable<? extends Publisher<? extends T>> onCompleteMapper) {
373+
ObjectHelper.requireNonNull(onErrorMapper, "onErrorMapper is null");
374+
ObjectHelper.requireNonNull(onCompleteMapper, "onCompleteMapper is null");
358375
// TODO implement
359376
throw new UnsupportedOperationException();
360377
}
@@ -401,47 +418,101 @@ public final <T> Maybe<T> toMaybe() {
401418
}
402419

403420
public final Nono subscribeOn(Scheduler scheduler) {
421+
ObjectHelper.requireNonNull(scheduler, "scheduler is null");
404422
return onAssembly(new NonoSubscribeOn(this, scheduler));
405423
}
406424

407425
public final Nono observeOn(Scheduler scheduler) {
426+
ObjectHelper.requireNonNull(scheduler, "scheduler is null");
408427
return onAssembly(new NonoObserveOn(this, scheduler));
409428
}
410429

411430
public final Nono unsubscribeOn(Scheduler scheduler) {
431+
ObjectHelper.requireNonNull(scheduler, "scheduler is null");
412432
// TODO implement
413433
throw new UnsupportedOperationException();
414434
}
415435

416436
public final Nono doOnComplete(Action action) {
437+
ObjectHelper.requireNonNull(action, "action is null");
417438
// TODO implement
418439
throw new UnsupportedOperationException();
419440
}
420441

421442
public final Nono doOnError(Consumer<? super Throwable> error) {
443+
ObjectHelper.requireNonNull(error, "error is null");
422444
// TODO implement
423445
throw new UnsupportedOperationException();
424446
}
425447

426448
public final Nono doAfterComplete(Action action) {
449+
ObjectHelper.requireNonNull(action, "action is null");
427450
// TODO implement
428451
throw new UnsupportedOperationException();
429452
}
430453

431454
public final Nono doAfterTerminate(Action action) {
455+
ObjectHelper.requireNonNull(action, "action is null");
432456
// TODO implement
433457
throw new UnsupportedOperationException();
434458
}
435459

436460
public final Nono doFinally(Action action) {
461+
ObjectHelper.requireNonNull(action, "action is null");
437462
// TODO implement
438463
throw new UnsupportedOperationException();
439464
}
440465

441466
public final Nono doOnCancel(Action action) {
467+
ObjectHelper.requireNonNull(action, "action is null");
468+
// TODO implement
469+
throw new UnsupportedOperationException();
470+
}
471+
472+
public final Nono repeat() {
473+
// TODO implement
474+
throw new UnsupportedOperationException();
475+
}
476+
477+
public final Nono repeat(long times) {
442478
// TODO implement
443479
throw new UnsupportedOperationException();
444480
}
481+
482+
public final Nono repeat(BooleanSupplier stop) {
483+
ObjectHelper.requireNonNull(stop, "stop is null");
484+
// TODO implement
485+
throw new UnsupportedOperationException();
486+
}
487+
488+
public final Nono repeatWhen(Function<Flowable<Object>, Publisher<?>> handler) {
489+
ObjectHelper.requireNonNull(handler, "handler is null");
490+
// TODO implement
491+
throw new UnsupportedOperationException();
492+
}
493+
494+
public final Nono retry() {
495+
// TODO implement
496+
throw new UnsupportedOperationException();
497+
}
498+
499+
public final Nono retry(long times) {
500+
// TODO implement
501+
throw new UnsupportedOperationException();
502+
}
503+
504+
public final Nono retry(Predicate<? super Throwable> predicate) {
505+
ObjectHelper.requireNonNull(predicate, "predicate is null");
506+
// TODO implement
507+
throw new UnsupportedOperationException();
508+
}
509+
510+
public final Nono retryWhen(Function<Flowable<Throwable>, Publisher<?>> handler) {
511+
ObjectHelper.requireNonNull(handler, "handler is null");
512+
// TODO implement
513+
throw new UnsupportedOperationException();
514+
}
515+
445516
// -----------------------------------------------------------
446517
// Consumers and subscribers (leave)
447518
// -----------------------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2016 David Karnok
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package hu.akarnokd.rxjava2.basetypes;
18+
19+
import org.reactivestreams.Subscriber;
20+
21+
import io.reactivex.exceptions.*;
22+
import io.reactivex.functions.Function;
23+
import io.reactivex.internal.functions.ObjectHelper;
24+
25+
/**
26+
* Map an upstream error into another Throwable.
27+
*/
28+
final class NonoMapError extends Nono {
29+
30+
final Nono source;
31+
32+
final Function<? super Throwable, ? extends Throwable> mapper;
33+
34+
NonoMapError(Nono source, Function<? super Throwable, ? extends Throwable> mapper) {
35+
this.source = source;
36+
this.mapper = mapper;
37+
}
38+
39+
@Override
40+
protected void subscribeActual(Subscriber<? super Void> s) {
41+
source.subscribe(new MapErrorSubscriber(s, mapper));
42+
}
43+
44+
static final class MapErrorSubscriber extends BasicNonoSubscriber {
45+
46+
final Function<? super Throwable, ? extends Throwable> mapper;
47+
48+
public MapErrorSubscriber(Subscriber<? super Void> actual, Function<? super Throwable, ? extends Throwable> mapper) {
49+
super(actual);
50+
this.mapper = mapper;
51+
}
52+
53+
@Override
54+
public void onError(Throwable t) {
55+
Throwable ex;
56+
try {
57+
ex = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null Throwable");
58+
} catch (Throwable exc) {
59+
Exceptions.throwIfFatal(exc);
60+
ex = new CompositeException(t, exc);
61+
}
62+
actual.onError(ex);
63+
}
64+
65+
@Override
66+
public void onComplete() {
67+
actual.onComplete();
68+
}
69+
70+
}
71+
}

0 commit comments

Comments
 (0)