Skip to content

Commit 78230e3

Browse files
authored
4.x: Disposable no longer impls AutoCloseable (#8184)
* 4.x: Disposable no longer impls AutoCloseable * Remove Disposable::close, fix code coverage
1 parent 5091ed2 commit 78230e3

96 files changed

Lines changed: 111 additions & 368 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ if (project.hasProperty("releaseMode")) {
297297
}
298298
mavenPublishing {
299299
// or when publishing to https://central.sonatype.com/
300-
publishToMavenCentral(true, DeploymentValidation.PUBLISHED)
300+
publishToMavenCentral(true, com.vanniktech.maven.publish.DeploymentValidation.PUBLISHED)
301301

302302
// signAllPublications()
303303
}

src/main/java/io/reactivex/rxjava4/disposables/Disposable.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/**
2626
* Represents a disposable resource.
2727
*/
28-
public interface Disposable extends AutoCloseable {
28+
public interface Disposable {
2929
/**
3030
* Dispose the resource, the operation should be idempotent.
3131
*/
@@ -37,14 +37,6 @@ public interface Disposable extends AutoCloseable {
3737
*/
3838
boolean isDisposed();
3939

40-
/**
41-
* Dispose the resource, the operation should be idempotent.
42-
* @since 4.0.0
43-
*/
44-
default void close() {
45-
dispose();
46-
}
47-
4840
/**
4941
* Construct a {@code Disposable} by wrapping a {@link Runnable} that is
5042
* executed exactly once when the {@code Disposable} is disposed.
@@ -75,9 +67,9 @@ static Disposable fromAction(@NonNull Action action) {
7567

7668
/**
7769
* Construct a {@code Disposable} by wrapping a {@link Future} that is
78-
* cancelled exactly once when the {@code Disposable} is disposed.
70+
* canceled exactly once when the {@code Disposable} is disposed.
7971
* <p>
80-
* The {@code Future} is cancelled with {@code mayInterruptIfRunning == true}.
72+
* The {@code Future} is canceled with {@code mayInterruptIfRunning == true}.
8173
* @param future the {@code Future} to wrap
8274
* @return the new {@code Disposable} instance
8375
* @throws NullPointerException if {@code future} is {@code null}
@@ -92,7 +84,7 @@ static Disposable fromFuture(@NonNull Future<?> future) {
9284

9385
/**
9486
* Construct a {@code Disposable} by wrapping a {@link Future} that is
95-
* cancelled exactly once when the {@code Disposable} is disposed.
87+
* canceled exactly once when the {@code Disposable} is disposed.
9688
* @param future the {@code Future} to wrap
9789
* @param allowInterrupt if true, the future cancel happens via {@code Future.cancel(true)}
9890
* @return the new {@code Disposable} instance
@@ -107,7 +99,7 @@ static Disposable fromFuture(@NonNull Future<?> future, boolean allowInterrupt)
10799

108100
/**
109101
* Construct a {@code Disposable} by wrapping a {@link Subscription} that is
110-
* cancelled exactly once when the {@code Disposable} is disposed.
102+
* canceled exactly once when the {@code Disposable} is disposed.
111103
* @param subscription the {@code Runnable} to wrap
112104
* @return the new {@code Disposable} instance
113105
* @throws NullPointerException if {@code subscription} is {@code null}
@@ -147,6 +139,17 @@ static AutoCloseable toAutoCloseable(@NonNull Disposable disposable) {
147139
return disposable::dispose;
148140
}
149141

142+
/**
143+
* Wraps this {@code Disposable} into an {@link AutoCloseable} instance
144+
* that can be used with try-with-resources constructs.
145+
* @return the new {@code AutoCloseable} instance
146+
* @since 4.0.0
147+
*/
148+
@NonNull
149+
default AutoCloseable asAutoCloseable() {
150+
return this::dispose;
151+
}
152+
150153
/**
151154
* Returns a new, non-disposed {@code Disposable} instance.
152155
* @return a new, non-disposed {@code Disposable} instance

src/main/java/io/reactivex/rxjava4/disposables/DisposableContainer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ default Disposable subscribe(Disposable d) {
9595
* cases where the dispose signal has no side effects to work with.
9696
* @since 4.0.0
9797
*/
98-
static DisposableContainer NEVER = new NeverDisposableContainer();
98+
DisposableContainer NEVER = new NeverDisposableContainer();
9999

100100
/**
101101
* Implementation of a never disposable container.
102102
* @since 4.0.0
103103
*/
104-
static record NeverDisposableContainer() implements DisposableContainer {
104+
record NeverDisposableContainer() implements DisposableContainer {
105105

106106
@Override
107107
public void dispose() {

src/main/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableRefCount.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ protected void subscribeActual(Subscriber<? super T> s) {
9292
}
9393
}
9494

95-
@SuppressWarnings("resource")
9695
void cancel(RefConnection rc) {
9796
SequentialDisposable sd;
9897
synchronized (this) {

src/main/java/io/reactivex/rxjava4/internal/operators/observable/ObservableAmb.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public void subscribeActual(Observer<? super T> observer) {
6969
return;
7070
}
7171

72-
@SuppressWarnings("resource")
7372
AmbCoordinator<T> ac = new AmbCoordinator<>(observer, count);
7473
ac.subscribe(sources);
7574
}

src/main/java/io/reactivex/rxjava4/internal/operators/observable/ObservableCombineLatest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public void subscribeActual(Observer<? super R> observer) {
7373
return;
7474
}
7575

76-
@SuppressWarnings("resource")
7776
LatestCoordinator<T, R> lc = new LatestCoordinator<>(observer, combiner, count, bufferSize, delayError);
7877
lc.subscribe(sources);
7978
}

src/main/java/io/reactivex/rxjava4/internal/operators/observable/ObservableRefCount.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ protected void subscribeActual(Observer<? super T> observer) {
8989
}
9090
}
9191

92-
@SuppressWarnings("resource")
9392
void cancel(RefConnection rc) {
9493
SequentialDisposable sd;
9594
synchronized (this) {

src/main/java/io/reactivex/rxjava4/internal/operators/observable/ObservableZip.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public void subscribeActual(Observer<? super R> observer) {
6969
return;
7070
}
7171

72-
@SuppressWarnings("resource")
7372
ZipCoordinator<T, R> zc = new ZipCoordinator<>(observer, zipper, count, delayError);
7473
zc.subscribe(sources, bufferSize);
7574
}

src/main/java/io/reactivex/rxjava4/internal/schedulers/DeferredExecutorScheduler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ public Disposable schedule(@NonNull Runnable run) {
105105
task = interruptibleTask;
106106
disposable = interruptibleTask;
107107
} else {
108-
@SuppressWarnings("resource")
109108
BooleanRunnable runnableTask = new BooleanRunnable(decoratedRun);
110109

111110
task = runnableTask;

src/main/java/io/reactivex/rxjava4/internal/schedulers/ExecutorScheduler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ public Disposable schedule(@NonNull Runnable run) {
167167
task = interruptibleTask;
168168
disposable = interruptibleTask;
169169
} else {
170-
@SuppressWarnings("resource")
171170
BooleanRunnable runnableTask = new BooleanRunnable(decoratedRun);
172171

173172
task = runnableTask;

0 commit comments

Comments
 (0)