Skip to content

Commit 07ddc7a

Browse files
authored
2.x: BaseTestConsumer values() and errors() thread-safety clarifications (#5713)
1 parent 3f9ffae commit 07ddc7a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/main/java/io/reactivex/observers/BaseTestConsumer.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ public final Thread lastThread() {
7575

7676
/**
7777
* Returns a shared list of received onNext values.
78+
* <p>
79+
* Note that accessing the items via certain methods of the {@link List}
80+
* interface while the upstream is still actively emitting
81+
* more items may result in a {@code ConcurrentModificationException}.
82+
* <p>
83+
* The {@link List#size()} method will return the number of items
84+
* already received by this TestObserver/TestSubscriber in a thread-safe
85+
* manner that can be read via {@link List#get(int)}) method
86+
* (index range of 0 to {@code List.size() - 1}).
87+
* <p>
88+
* A view of the returned List can be created via {@link List#subList(int, int)}
89+
* by using the bounds 0 (inclusive) to {@link List#size()} (exclusive) which,
90+
* when accessed in a read-only fashion, should be also thread-safe and not throw any
91+
* {@code ConcurrentModificationException}.
7892
* @return a list of received onNext values
7993
*/
8094
public final List<T> values() {
@@ -83,6 +97,20 @@ public final List<T> values() {
8397

8498
/**
8599
* Returns a shared list of received onError exceptions.
100+
* <p>
101+
* Note that accessing the errors via certain methods of the {@link List}
102+
* interface while the upstream is still actively emitting
103+
* more items or errors may result in a {@code ConcurrentModificationException}.
104+
* <p>
105+
* The {@link List#size()} method will return the number of errors
106+
* already received by this TestObserver/TestSubscriber in a thread-safe
107+
* manner that can be read via {@link List#get(int)}) method
108+
* (index range of 0 to {@code List.size() - 1}).
109+
* <p>
110+
* A view of the returned List can be created via {@link List#subList(int, int)}
111+
* by using the bounds 0 (inclusive) to {@link List#size()} (exclusive) which,
112+
* when accessed in a read-only fashion, should be also thread-safe and not throw any
113+
* {@code ConcurrentModificationException}.
86114
* @return a list of received events onError exceptions
87115
*/
88116
public final List<Throwable> errors() {

0 commit comments

Comments
 (0)