Skip to content
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

[Proposal] Remove CheckReturnValue on subscribe() overloads #6304

Closed
Closed
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: 2 additions & 2 deletions src/main/java/io/reactivex/Completable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ public final <E extends CompletableObserver> E subscribeWith(E observer) {
* @return the Disposable that can be used for disposing the subscription asynchronously
* @throws NullPointerException if either callback is null
*/
@CheckReturnValue
@OptionalCheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(final Action onComplete, final Consumer<? super Throwable> onError) {
ObjectHelper.requireNonNull(onError, "onError is null");
Expand All @@ -2345,7 +2345,7 @@ public final Disposable subscribe(final Action onComplete, final Consumer<? supe
* @param onComplete the runnable called when this Completable completes normally
* @return the Disposable that allows disposing the subscription
*/
@CheckReturnValue
@OptionalCheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(final Action onComplete) {
ObjectHelper.requireNonNull(onComplete, "onComplete is null");
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/reactivex/Flowable.java
Original file line number Diff line number Diff line change
Expand Up @@ -14455,7 +14455,7 @@ public final Disposable subscribe() {
* if {@code onNext} is null
* @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX operators documentation: Subscribe</a>
*/
@CheckReturnValue
@OptionalCheckReturnValue
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(Consumer<? super T> onNext) {
Expand Down Expand Up @@ -14486,7 +14486,7 @@ public final Disposable subscribe(Consumer<? super T> onNext) {
* if {@code onNext} is null, or
* if {@code onError} is null
*/
@CheckReturnValue
@OptionalCheckReturnValue
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError) {
Expand Down Expand Up @@ -14520,7 +14520,7 @@ public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super T
* if {@code onComplete} is null
* @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX operators documentation: Subscribe</a>
*/
@CheckReturnValue
@OptionalCheckReturnValue
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError,
Expand Down Expand Up @@ -14558,7 +14558,7 @@ public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super T
* if {@code onSubscribe} is null
* @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX operators documentation: Subscribe</a>
*/
@CheckReturnValue
@OptionalCheckReturnValue
@BackpressureSupport(BackpressureKind.SPECIAL)
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError,
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/reactivex/Maybe.java
Original file line number Diff line number Diff line change
Expand Up @@ -4095,7 +4095,7 @@ public final Disposable subscribe() {
* if {@code onSuccess} is null
* @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX operators documentation: Subscribe</a>
*/
@CheckReturnValue
@OptionalCheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(Consumer<? super T> onSuccess) {
return subscribe(onSuccess, Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION);
Expand All @@ -4121,7 +4121,7 @@ public final Disposable subscribe(Consumer<? super T> onSuccess) {
* if {@code onSuccess} is null, or
* if {@code onError} is null
*/
@CheckReturnValue
@OptionalCheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(Consumer<? super T> onSuccess, Consumer<? super Throwable> onError) {
return subscribe(onSuccess, onError, Functions.EMPTY_ACTION);
Expand Down Expand Up @@ -4151,7 +4151,7 @@ public final Disposable subscribe(Consumer<? super T> onSuccess, Consumer<? supe
* if {@code onComplete} is null
* @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX operators documentation: Subscribe</a>
*/
@CheckReturnValue
@OptionalCheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(Consumer<? super T> onSuccess, Consumer<? super Throwable> onError,
Action onComplete) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/reactivex/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -12079,7 +12079,7 @@ public final Disposable subscribe() {
* if {@code onNext} is null
* @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX operators documentation: Subscribe</a>
*/
@CheckReturnValue
@OptionalCheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(Consumer<? super T> onNext) {
return subscribe(onNext, Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION, Functions.emptyConsumer());
Expand All @@ -12105,7 +12105,7 @@ public final Disposable subscribe(Consumer<? super T> onNext) {
* if {@code onNext} is null, or
* if {@code onError} is null
*/
@CheckReturnValue
@OptionalCheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError) {
return subscribe(onNext, onError, Functions.EMPTY_ACTION, Functions.emptyConsumer());
Expand Down Expand Up @@ -12135,7 +12135,7 @@ public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super T
* if {@code onComplete} is null
* @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX operators documentation: Subscribe</a>
*/
@CheckReturnValue
@OptionalCheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError,
Action onComplete) {
Expand Down Expand Up @@ -12169,7 +12169,7 @@ public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super T
* if {@code onSubscribe} is null
* @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX operators documentation: Subscribe</a>
*/
@CheckReturnValue
@OptionalCheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError,
Action onComplete, Consumer<? super Disposable> onSubscribe) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/reactivex/Single.java
Original file line number Diff line number Diff line change
Expand Up @@ -3418,7 +3418,7 @@ public final Disposable subscribe() {
* @throws NullPointerException
* if {@code onCallback} is null
*/
@CheckReturnValue
@OptionalCheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(final BiConsumer<? super T, ? super Throwable> onCallback) {
ObjectHelper.requireNonNull(onCallback, "onCallback is null");
Expand Down Expand Up @@ -3446,7 +3446,7 @@ public final Disposable subscribe(final BiConsumer<? super T, ? super Throwable>
* if {@code onSuccess} is null
* @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX operators documentation: Subscribe</a>
*/
@CheckReturnValue
@OptionalCheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(Consumer<? super T> onSuccess) {
return subscribe(onSuccess, Functions.ON_ERROR_MISSING);
Expand All @@ -3471,7 +3471,7 @@ public final Disposable subscribe(Consumer<? super T> onSuccess) {
* if {@code onSuccess} is null, or
* if {@code onError} is null
*/
@CheckReturnValue
@OptionalCheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(final Consumer<? super T> onSuccess, final Consumer<? super Throwable> onError) {
ObjectHelper.requireNonNull(onSuccess, "onSuccess is null");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2016-present, RxJava Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations under the License.
*/

package io.reactivex.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Marks methods whose return values should be optionally checked by separate tooling.
* <p>History: 2.2.4 - experimental
* @since 2.2.4
*/
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Target(ElementType.METHOD)
public @interface OptionalCheckReturnValue {

}
14 changes: 10 additions & 4 deletions src/test/java/io/reactivex/validators/BaseTypeAnnotations.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,18 @@ static void checkCheckReturnValueSupport(Class<?> clazz) {
continue;
}
if (m.getDeclaringClass() == clazz) {
boolean isSubscribeMethod = "subscribe".equals(m.getName()) && m.getParameterTypes().length == 0;
boolean isSubscribeMethod = "subscribe".equals(m.getName());
boolean isNoArgSubscribeMethod = isSubscribeMethod && m.getParameterTypes().length == 0;
boolean isAnnotationPresent = m.isAnnotationPresent(CheckReturnValue.class);
boolean isVoid = m.getReturnType().equals(Void.TYPE);

if (isSubscribeMethod) {
if (isAnnotationPresent) {
b.append("subscribe() method has @CheckReturnValue: ").append(m).append("\r\n");
if (isNoArgSubscribeMethod) {
if (isAnnotationPresent) {
b.append("subscribe() method has @CheckReturnValue: ").append(m).append("\r\n");
}
} else if (!isVoid && !m.isAnnotationPresent(OptionalCheckReturnValue.class)) {
b.append("subscribe() method missing @OptionalCheckReturnValue: ").append(m).append("\r\n");
}
continue;
}
Expand All @@ -57,7 +63,7 @@ static void checkCheckReturnValueSupport(Class<?> clazz) {
continue;
}

if (m.getReturnType().equals(Void.TYPE)) {
if (isVoid) {
if (isAnnotationPresent) {
b.append("Void method has @CheckReturnValue: ").append(m).append("\r\n");
}
Expand Down