From f2a12f4fd0eeb4f2b01ddc31d11d7f82b05b5540 Mon Sep 17 00:00:00 2001 From: akarnokd Date: Thu, 9 Nov 2017 14:00:53 +0100 Subject: [PATCH] 2.x: BaseTestConsumer values() and errors() thread-safety clarifications --- .../reactivex/observers/BaseTestConsumer.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/io/reactivex/observers/BaseTestConsumer.java b/src/main/java/io/reactivex/observers/BaseTestConsumer.java index 8144a22c40..a1598c5732 100644 --- a/src/main/java/io/reactivex/observers/BaseTestConsumer.java +++ b/src/main/java/io/reactivex/observers/BaseTestConsumer.java @@ -75,6 +75,20 @@ public final Thread lastThread() { /** * Returns a shared list of received onNext values. + *

+ * Note that accessing the items via certain methods of the {@link List} + * interface while the upstream is still actively emitting + * more items may result in a {@code ConcurrentModificationException}. + *

+ * The {@link List#size()} method will return the number of items + * already received by this TestObserver/TestSubscriber in a thread-safe + * manner that can be read via {@link List#get(int)}) method + * (index range of 0 to {@code List.size() - 1}). + *

+ * A view of the returned List can be created via {@link List#subList(int, int)} + * by using the bounds 0 (inclusive) to {@link List#size()} (exclusive) which, + * when accessed in a read-only fashion, should be also thread-safe and not throw any + * {@code ConcurrentModificationException}. * @return a list of received onNext values */ public final List values() { @@ -83,6 +97,20 @@ public final List values() { /** * Returns a shared list of received onError exceptions. + *

+ * Note that accessing the errors via certain methods of the {@link List} + * interface while the upstream is still actively emitting + * more items or errors may result in a {@code ConcurrentModificationException}. + *

+ * The {@link List#size()} method will return the number of errors + * already received by this TestObserver/TestSubscriber in a thread-safe + * manner that can be read via {@link List#get(int)}) method + * (index range of 0 to {@code List.size() - 1}). + *

+ * A view of the returned List can be created via {@link List#subList(int, int)} + * by using the bounds 0 (inclusive) to {@link List#size()} (exclusive) which, + * when accessed in a read-only fashion, should be also thread-safe and not throw any + * {@code ConcurrentModificationException}. * @return a list of received events onError exceptions */ public final List errors() {