Skip to content

Commit f3d8583

Browse files
authored
3.x: Fix ExecutorScheduler initializing Schedulers prematurely (#7323)
* 3.x: Fix ExecutorScheduler initializing Schedulers prematurely * Add coverage of the holder class
1 parent 9de33ea commit f3d8583

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public final class ExecutorScheduler extends Scheduler {
3838
@NonNull
3939
final Executor executor;
4040

41-
static final Scheduler HELPER = Schedulers.single();
41+
static final class SingleHolder {
42+
static final Scheduler HELPER = Schedulers.single();
43+
}
4244

4345
public ExecutorScheduler(@NonNull Executor executor, boolean interruptibleWorker, boolean fair) {
4446
this.executor = executor;
@@ -97,7 +99,7 @@ public Disposable scheduleDirect(@NonNull Runnable run, final long delay, final
9799

98100
final DelayedRunnable dr = new DelayedRunnable(decoratedRun);
99101

100-
Disposable delayed = HELPER.scheduleDirect(new DelayedDispose(dr), delay, unit);
102+
Disposable delayed = SingleHolder.HELPER.scheduleDirect(new DelayedDispose(dr), delay, unit);
101103

102104
dr.timed.replace(delayed);
103105

@@ -215,7 +217,7 @@ public Disposable schedule(@NonNull Runnable run, long delay, @NonNull TimeUnit
215217
return EmptyDisposable.INSTANCE;
216218
}
217219
} else {
218-
final Disposable d = HELPER.scheduleDirect(sr, delay, unit);
220+
final Disposable d = SingleHolder.HELPER.scheduleDirect(sr, delay, unit);
219221
sr.setFuture(new DisposeOnCancel(d));
220222
}
221223

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2016-present, RxJava Contributors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5+
* compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
10+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11+
* the License for the specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package io.reactivex.rxjava3.internal.schedulers;
15+
16+
import static org.junit.Assert.assertNotNull;
17+
18+
import org.junit.Test;
19+
20+
public class ExecutorSchedulerInternalTest {
21+
22+
@Test
23+
public void helperHolder() {
24+
assertNotNull(new ExecutorScheduler.SingleHolder());
25+
}
26+
27+
}

0 commit comments

Comments
 (0)