Skip to content

2.x: Fix & prevent null checks on primitives #6014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/main/java/io/reactivex/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1455,8 +1455,6 @@ public static <T> Observable<T> concatEager(ObservableSource<? extends Observabl
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static <T> Observable<T> concatEager(ObservableSource<? extends ObservableSource<? extends T>> sources, int maxConcurrency, int prefetch) {
ObjectHelper.requireNonNull(maxConcurrency, "maxConcurrency is null");
ObjectHelper.requireNonNull(prefetch, "prefetch is null");
return wrap(sources).concatMapEager((Function)Functions.identity(), maxConcurrency, prefetch);
}

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

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/io/reactivex/internal/functions/ObjectHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,17 @@ public boolean test(Object o1, Object o2) {
return ObjectHelper.equals(o1, o2);
}
}

/**
* Trap null-check attempts on primitives.
* @param value the value to check
* @param message the message to print
* @return the value
* @deprecated this method should not be used as there is no need
* to check primitives for nullness.
*/
@Deprecated
public static long requireNonNull(long value, String message) {
throw new InternalError("Null check on a primitive: " + message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not the best choice of error type, InternalError indicates JVM error, combined with "Null check on a primitive" message might mislead the developer into thinking that something is wrong with bytecode/VM hehe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially if they run a value types enabled vm ;)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ public void compareLong() {
assertEquals(0, ObjectHelper.compare(0L, 0L));
assertEquals(1, ObjectHelper.compare(2L, 0L));
}

@SuppressWarnings("deprecation")
@Test(expected = InternalError.class)
public void requireNonNullPrimitive() {
ObjectHelper.requireNonNull(0, "value");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ public void subscribe(FlowableEmitter<Object> e) throws Exception {
}
}

@SuppressWarnings("rawtypes")
@Test
public void emittersHasToString() {
Map<BackpressureStrategy, Class<? extends FlowableEmitter>> emitterMap =
Expand Down