Skip to content

Commit 89581b4

Browse files
authored
2.x: additional warnings for fromPublisher() (#5640)
* 2.x: additional warnings for fromPublisher() * Add "that is" to the sentences
1 parent 182de28 commit 89581b4

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

src/main/java/io/reactivex/Completable.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,17 @@ public static <T> Completable fromObservable(final ObservableSource<T> observabl
394394
/**
395395
* Returns a Completable instance that subscribes to the given publisher, ignores all values and
396396
* emits only the terminal event.
397+
* <p>
398+
* The {@link Publisher} must follow the
399+
* <a href="https://github.com/reactive-streams/reactive-streams-jvm#reactive-streams">Reactive-Streams specification</a>.
400+
* Violating the specification may result in undefined behavior.
401+
* <p>
402+
* If possible, use {@link #create(CompletableOnSubscribe)} to create a
403+
* source-like {@code Completable} instead.
404+
* <p>
405+
* Note that even though {@link Publisher} appears to be a functional interface, it
406+
* is not recommended to implement it through a lambda as the specification requires
407+
* state management that is not achievable with a stateless lambda.
397408
* <dl>
398409
* <dt><b>Backpressure:</b></dt>
399410
* <dd>The returned {@code Completable} honors the backpressure of the downstream consumer
@@ -405,6 +416,7 @@ public static <T> Completable fromObservable(final ObservableSource<T> observabl
405416
* @param publisher the Publisher instance to subscribe to, not null
406417
* @return the new Completable instance
407418
* @throws NullPointerException if publisher is null
419+
* @see #create(CompletableOnSubscribe)
408420
*/
409421
@CheckReturnValue
410422
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)

src/main/java/io/reactivex/Flowable.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,6 +2094,17 @@ public static <T> Flowable<T> fromIterable(Iterable<? extends T> source) {
20942094
/**
20952095
* Converts an arbitrary Reactive-Streams Publisher into a Flowable if not already a
20962096
* Flowable.
2097+
* <p>
2098+
* The {@link Publisher} must follow the
2099+
* <a href="https://github.com/reactive-streams/reactive-streams-jvm#reactive-streams">Reactive-Streams specification</a>.
2100+
* Violating the specification may result in undefined behavior.
2101+
* <p>
2102+
* If possible, use {@link #create(FlowableOnSubscribe, BackpressureStrategy)} to create a
2103+
* source-like {@code Flowable} instead.
2104+
* <p>
2105+
* Note that even though {@link Publisher} appears to be a functional interface, it
2106+
* is not recommended to implement it through a lambda as the specification requires
2107+
* state management that is not achievable with a stateless lambda.
20972108
* <dl>
20982109
* <dt><b>Backpressure:</b></dt>
20992110
* <dd>The operator is a pass-through for backpressure and its behavior is determined by the
@@ -2105,6 +2116,7 @@ public static <T> Flowable<T> fromIterable(Iterable<? extends T> source) {
21052116
* @param source the Publisher to convert
21062117
* @return the new Flowable instance
21072118
* @throws NullPointerException if publisher is null
2119+
* @see #create(FlowableOnSubscribe, BackpressureStrategy)
21082120
*/
21092121
@CheckReturnValue
21102122
@BackpressureSupport(BackpressureKind.PASS_THROUGH)

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,17 @@ public static <T> Observable<T> fromIterable(Iterable<? extends T> source) {
18971897

18981898
/**
18991899
* Converts an arbitrary Reactive-Streams Publisher into an Observable.
1900+
* <p>
1901+
* The {@link Publisher} must follow the
1902+
* <a href="https://github.com/reactive-streams/reactive-streams-jvm#reactive-streams">Reactive-Streams specification</a>.
1903+
* Violating the specification may result in undefined behavior.
1904+
* <p>
1905+
* If possible, use {@link #create(ObservableOnSubscribe)} to create a
1906+
* source-like {@code Observable} instead.
1907+
* <p>
1908+
* Note that even though {@link Publisher} appears to be a functional interface, it
1909+
* is not recommended to implement it through a lambda as the specification requires
1910+
* state management that is not achievable with a stateless lambda.
19001911
* <dl>
19011912
* <dt><b>Backpressure:</b></dt>
19021913
* <dd>The source {@code publisher} is consumed in an unbounded fashion without applying any
@@ -1908,6 +1919,7 @@ public static <T> Observable<T> fromIterable(Iterable<? extends T> source) {
19081919
* @param publisher the Publisher to convert
19091920
* @return the new Observable instance
19101921
* @throws NullPointerException if publisher is null
1922+
* @see #create(ObservableOnSubscribe)
19111923
*/
19121924
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
19131925
@CheckReturnValue

src/main/java/io/reactivex/Single.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,17 @@ public static <T> Single<T> fromFuture(Future<? extends T> future, Scheduler sch
578578
* Wraps a specific Publisher into a Single and signals its single element or error.
579579
* <p>If the source Publisher is empty, a NoSuchElementException is signalled. If
580580
* the source has more than one element, an IndexOutOfBoundsException is signalled.
581+
* <p>
582+
* The {@link Publisher} must follow the
583+
* <a href="https://github.com/reactive-streams/reactive-streams-jvm#reactive-streams">Reactive-Streams specification</a>.
584+
* Violating the specification may result in undefined behavior.
585+
* <p>
586+
* If possible, use {@link #create(SingleOnSubscribe)} to create a
587+
* source-like {@code Single} instead.
588+
* <p>
589+
* Note that even though {@link Publisher} appears to be a functional interface, it
590+
* is not recommended to implement it through a lambda as the specification requires
591+
* state management that is not achievable with a stateless lambda.
581592
* <dl>
582593
* <dt><b>Backpressure:</b></dt>
583594
* <dd>The {@code publisher} is consumed in an unbounded fashion but will be cancelled
@@ -588,6 +599,7 @@ public static <T> Single<T> fromFuture(Future<? extends T> future, Scheduler sch
588599
* @param <T> the value type
589600
* @param publisher the source Publisher instance, not null
590601
* @return the new Single instance
602+
* @see #create(SingleOnSubscribe)
591603
*/
592604
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
593605
@CheckReturnValue

0 commit comments

Comments
 (0)