Skip to content

Commit 4f1b09c

Browse files
Merge pull request #1513 from benjchristensen/to-list-copy
Revert to copying list in toList
2 parents a07e837 + 69868d5 commit 4f1b09c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

rxjava-core/src/main/java/rx/internal/operators/OperatorToObservableList.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,22 @@ public void onStart() {
5555
public void onCompleted() {
5656
try {
5757
completed = true;
58-
o.onNext(Collections.unmodifiableList(list));
58+
/*
59+
* Ideally this should just return Collections.unmodifiableList(list) and not copy it,
60+
* but, it ends up being a breaking change if we make that modification.
61+
*
62+
* Here is an example of is being done with these lists that breaks if we make it immutable:
63+
*
64+
* Caused by: java.lang.UnsupportedOperationException
65+
* at java.util.Collections$UnmodifiableList$1.set(Collections.java:1244)
66+
* at java.util.Collections.sort(Collections.java:221)
67+
* ...
68+
* Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: UnmodifiableList.class
69+
* at rx.exceptions.OnErrorThrowable.addValueAsLastCause(OnErrorThrowable.java:98)
70+
* at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:56)
71+
* ... 419 more
72+
*/
73+
o.onNext(new ArrayList<T>(list));
5974
o.onCompleted();
6075
} catch (Throwable e) {
6176
onError(e);

0 commit comments

Comments
 (0)