@@ -157,11 +157,16 @@ protected Observable() {
157
157
* @param observer
158
158
* @return a {@link Subscription} reference that allows observers
159
159
* to stop receiving notifications before the provider has finished sending them
160
+ * @throws IllegalArgumentException
161
+ * if null argument provided
160
162
*/
161
163
public Subscription subscribe (Observer <T > observer ) {
162
164
// allow the hook to intercept and/or decorate
163
165
Func1 <Observer <T >, Subscription > onSubscribeFunction = hook .onSubscribeStart (this , onSubscribe );
164
166
// validate and proceed
167
+ if (observer == null ) {
168
+ throw new IllegalArgumentException ("observer can not be null" );
169
+ }
165
170
if (onSubscribeFunction == null ) {
166
171
throw new IllegalStateException ("onSubscribe function can not be null." );
167
172
// the subscribe function can also be overridden but generally that's not the appropriate approach so I won't mention that in the exception
@@ -224,6 +229,8 @@ public Subscription subscribe(Observer<T> observer) {
224
229
* The {@link Scheduler} that the sequence is subscribed to on.
225
230
* @return a {@link Subscription} reference that allows observers
226
231
* to stop receiving notifications before the provider has finished sending them
232
+ * @throws IllegalArgumentException
233
+ * if null argument provided
227
234
*/
228
235
public Subscription subscribe (Observer <T > observer , Scheduler scheduler ) {
229
236
return subscribeOn (scheduler ).subscribe (observer );
@@ -241,11 +248,14 @@ private Subscription protectivelyWrapAndSubscribe(Observer<T> o) {
241
248
242
249
@ SuppressWarnings ({ "rawtypes" , "unchecked" })
243
250
public Subscription subscribe (final Map <String , Object > callbacks ) {
244
- // lookup and memoize onNext
251
+ if (callbacks == null ) {
252
+ throw new RuntimeException ("callbacks map can not be null" );
253
+ }
245
254
Object _onNext = callbacks .get ("onNext" );
246
255
if (_onNext == null ) {
247
- throw new RuntimeException ("onNext must be implemented " );
256
+ throw new RuntimeException ("' onNext' key must contain an implementation " );
248
257
}
258
+ // lookup and memoize onNext
249
259
final FuncN onNext = Functions .from (_onNext );
250
260
251
261
/**
@@ -291,10 +301,11 @@ public Subscription subscribe(final Object o) {
291
301
return subscribe ((Observer ) o );
292
302
}
293
303
294
- // lookup and memoize onNext
295
304
if (o == null ) {
296
- throw new RuntimeException ("onNext must be implemented " );
305
+ throw new IllegalArgumentException ("onNext can not be null " );
297
306
}
307
+
308
+ // lookup and memoize onNext
298
309
final FuncN onNext = Functions .from (o );
299
310
300
311
/**
@@ -328,6 +339,9 @@ public Subscription subscribe(final Object o, Scheduler scheduler) {
328
339
}
329
340
330
341
public Subscription subscribe (final Action1 <T > onNext ) {
342
+ if (onNext == null ) {
343
+ throw new IllegalArgumentException ("onNext can not be null" );
344
+ }
331
345
332
346
/**
333
347
* Wrapping since raw functions provided by the user are being invoked.
@@ -349,9 +363,6 @@ public void onError(Exception e) {
349
363
350
364
@ Override
351
365
public void onNext (T args ) {
352
- if (onNext == null ) {
353
- throw new RuntimeException ("onNext must be implemented" );
354
- }
355
366
onNext .call (args );
356
367
}
357
368
@@ -364,10 +375,14 @@ public Subscription subscribe(final Action1<T> onNext, Scheduler scheduler) {
364
375
365
376
@ SuppressWarnings ({ "rawtypes" , "unchecked" })
366
377
public Subscription subscribe (final Object onNext , final Object onError ) {
367
- // lookup and memoize onNext
368
378
if (onNext == null ) {
369
- throw new RuntimeException ("onNext must be implemented" );
379
+ throw new IllegalArgumentException ("onNext can not be null" );
380
+ }
381
+ if (onError == null ) {
382
+ throw new IllegalArgumentException ("onError can not be null" );
370
383
}
384
+
385
+ // lookup and memoize onNext
371
386
final FuncN onNextFunction = Functions .from (onNext );
372
387
373
388
/**
@@ -385,9 +400,7 @@ public void onCompleted() {
385
400
@ Override
386
401
public void onError (Exception e ) {
387
402
handleError (e );
388
- if (onError != null ) {
389
- Functions .from (onError ).call (e );
390
- }
403
+ Functions .from (onError ).call (e );
391
404
}
392
405
393
406
@ Override
@@ -403,6 +416,12 @@ public Subscription subscribe(final Object onNext, final Object onError, Schedul
403
416
}
404
417
405
418
public Subscription subscribe (final Action1 <T > onNext , final Action1 <Exception > onError ) {
419
+ if (onNext == null ) {
420
+ throw new IllegalArgumentException ("onNext can not be null" );
421
+ }
422
+ if (onError == null ) {
423
+ throw new IllegalArgumentException ("onError can not be null" );
424
+ }
406
425
407
426
/**
408
427
* Wrapping since raw functions provided by the user are being invoked.
@@ -419,16 +438,11 @@ public void onCompleted() {
419
438
@ Override
420
439
public void onError (Exception e ) {
421
440
handleError (e );
422
- if (onError != null ) {
423
- onError .call (e );
424
- }
441
+ onError .call (e );
425
442
}
426
443
427
444
@ Override
428
445
public void onNext (T args ) {
429
- if (onNext == null ) {
430
- throw new RuntimeException ("onNext must be implemented" );
431
- }
432
446
onNext .call (args );
433
447
}
434
448
@@ -441,10 +455,17 @@ public Subscription subscribe(final Action1<T> onNext, final Action1<Exception>
441
455
442
456
@ SuppressWarnings ({ "rawtypes" , "unchecked" })
443
457
public Subscription subscribe (final Object onNext , final Object onError , final Object onComplete ) {
444
- // lookup and memoize onNext
445
458
if (onNext == null ) {
446
- throw new RuntimeException ("onNext must be implemented" );
459
+ throw new IllegalArgumentException ("onNext can not be null" );
460
+ }
461
+ if (onError == null ) {
462
+ throw new IllegalArgumentException ("onError can not be null" );
447
463
}
464
+ if (onComplete == null ) {
465
+ throw new IllegalArgumentException ("onComplete can not be null" );
466
+ }
467
+
468
+ // lookup and memoize onNext
448
469
final FuncN onNextFunction = Functions .from (onNext );
449
470
450
471
/**
@@ -456,17 +477,13 @@ public Subscription subscribe(final Object onNext, final Object onError, final O
456
477
457
478
@ Override
458
479
public void onCompleted () {
459
- if (onComplete != null ) {
460
- Functions .from (onComplete ).call ();
461
- }
480
+ Functions .from (onComplete ).call ();
462
481
}
463
482
464
483
@ Override
465
484
public void onError (Exception e ) {
466
485
handleError (e );
467
- if (onError != null ) {
468
- Functions .from (onError ).call (e );
469
- }
486
+ Functions .from (onError ).call (e );
470
487
}
471
488
472
489
@ Override
@@ -482,6 +499,15 @@ public Subscription subscribe(final Object onNext, final Object onError, final O
482
499
}
483
500
484
501
public Subscription subscribe (final Action1 <T > onNext , final Action1 <Exception > onError , final Action0 onComplete ) {
502
+ if (onNext == null ) {
503
+ throw new IllegalArgumentException ("onNext can not be null" );
504
+ }
505
+ if (onError == null ) {
506
+ throw new IllegalArgumentException ("onError can not be null" );
507
+ }
508
+ if (onComplete == null ) {
509
+ throw new IllegalArgumentException ("onComplete can not be null" );
510
+ }
485
511
486
512
/**
487
513
* Wrapping since raw functions provided by the user are being invoked.
@@ -498,16 +524,11 @@ public void onCompleted() {
498
524
@ Override
499
525
public void onError (Exception e ) {
500
526
handleError (e );
501
- if (onError != null ) {
502
- onError .call (e );
503
- }
527
+ onError .call (e );
504
528
}
505
529
506
530
@ Override
507
531
public void onNext (T args ) {
508
- if (onNext == null ) {
509
- throw new RuntimeException ("onNext must be implemented" );
510
- }
511
532
onNext .call (args );
512
533
}
513
534
0 commit comments