Skip to content

Commit 4af78a7

Browse files
authored
2.x: Fix & prevent null checks on primitives (#6014)
1 parent 5f1ce20 commit 4af78a7

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

src/main/java/io/reactivex/Observable.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,8 +1455,6 @@ public static <T> Observable<T> concatEager(ObservableSource<? extends Observabl
14551455
@CheckReturnValue
14561456
@SchedulerSupport(SchedulerSupport.NONE)
14571457
public static <T> Observable<T> concatEager(ObservableSource<? extends ObservableSource<? extends T>> sources, int maxConcurrency, int prefetch) {
1458-
ObjectHelper.requireNonNull(maxConcurrency, "maxConcurrency is null");
1459-
ObjectHelper.requireNonNull(prefetch, "prefetch is null");
14601458
return wrap(sources).concatMapEager((Function)Functions.identity(), maxConcurrency, prefetch);
14611459
}
14621460

@@ -1507,8 +1505,6 @@ public static <T> Observable<T> concatEager(Iterable<? extends ObservableSource<
15071505
@CheckReturnValue
15081506
@SchedulerSupport(SchedulerSupport.NONE)
15091507
public static <T> Observable<T> concatEager(Iterable<? extends ObservableSource<? extends T>> sources, int maxConcurrency, int prefetch) {
1510-
ObjectHelper.requireNonNull(maxConcurrency, "maxConcurrency is null");
1511-
ObjectHelper.requireNonNull(prefetch, "prefetch is null");
15121508
return fromIterable(sources).concatMapEagerDelayError((Function)Functions.identity(), maxConcurrency, prefetch, false);
15131509
}
15141510

src/main/java/io/reactivex/internal/functions/ObjectHelper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,17 @@ public boolean test(Object o1, Object o2) {
128128
return ObjectHelper.equals(o1, o2);
129129
}
130130
}
131+
132+
/**
133+
* Trap null-check attempts on primitives.
134+
* @param value the value to check
135+
* @param message the message to print
136+
* @return the value
137+
* @deprecated this method should not be used as there is no need
138+
* to check primitives for nullness.
139+
*/
140+
@Deprecated
141+
public static long requireNonNull(long value, String message) {
142+
throw new InternalError("Null check on a primitive: " + message);
143+
}
131144
}

src/test/java/io/reactivex/internal/functions/ObjectHelperTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,10 @@ public void compareLong() {
6565
assertEquals(0, ObjectHelper.compare(0L, 0L));
6666
assertEquals(1, ObjectHelper.compare(2L, 0L));
6767
}
68+
69+
@SuppressWarnings("deprecation")
70+
@Test(expected = InternalError.class)
71+
public void requireNonNullPrimitive() {
72+
ObjectHelper.requireNonNull(0, "value");
73+
}
6874
}

src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ public void subscribe(FlowableEmitter<Object> e) throws Exception {
934934
}
935935
}
936936

937+
@SuppressWarnings("rawtypes")
937938
@Test
938939
public void emittersHasToString() {
939940
Map<BackpressureStrategy, Class<? extends FlowableEmitter>> emitterMap =

0 commit comments

Comments
 (0)