Skip to content

Commit 9b44404

Browse files
mekarthedevakarnokd
authored andcommitted
Fixed conditional iteration breaking. (#5952)
1 parent 3481424 commit 9b44404

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/main/java/io/reactivex/internal/util/AppendOnlyLinkedArrayList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void forEachWhile(NonThrowingPredicate<? super T> consumer) {
9191
break;
9292
}
9393
if (consumer.test((T)o)) {
94-
break;
94+
return;
9595
}
9696
}
9797
a = (Object[])a[c];

src/test/java/io/reactivex/internal/util/MiscUtilTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@ public void appendOnlyLinkedArrayListForEachWhile() throws Exception {
7575

7676
final List<Integer> out = new ArrayList<Integer>();
7777

78+
list.forEachWhile(new NonThrowingPredicate<Integer>() {
79+
@Override
80+
public boolean test(Integer t2) {
81+
out.add(t2);
82+
return t2 == 2;
83+
}
84+
});
85+
86+
assertEquals(Arrays.asList(1, 2), out);
87+
}
88+
89+
@Test
90+
public void appendOnlyLinkedArrayListForEachWhileBi() throws Exception {
91+
AppendOnlyLinkedArrayList<Integer> list = new AppendOnlyLinkedArrayList<Integer>(2);
92+
93+
list.add(1);
94+
list.add(2);
95+
list.add(3);
96+
97+
final List<Integer> out = new ArrayList<Integer>();
98+
7899
list.forEachWhile(2, new BiPredicate<Integer, Integer>() {
79100
@Override
80101
public boolean test(Integer t1, Integer t2) throws Exception {
@@ -86,7 +107,6 @@ public boolean test(Integer t1, Integer t2) throws Exception {
86107
assertEquals(Arrays.asList(1, 2), out);
87108
}
88109

89-
90110
@Test
91111
public void appendOnlyLinkedArrayListForEachWhilePreGrow() throws Exception {
92112
AppendOnlyLinkedArrayList<Integer> list = new AppendOnlyLinkedArrayList<Integer>(12);

0 commit comments

Comments
 (0)