Commit f995b98
Fix NullPointerException in AppendOnlyLinkedArrayList.forEachWhile on a full last chunk (#8174)
* Fix NullPointerException in AppendOnlyLinkedArrayList.forEachWhile on a full last chunk
forEachWhile(S, BiPredicate) walks the linked chunks and, after iterating a
chunk, follows the next-chunk pointer stored at a[capacity]. When the list size
is exactly a multiple of the chunk capacity the last chunk is full but its
next-chunk pointer has not been allocated yet (it is null), so `a` becomes null
and the next iteration throws NullPointerException reading a[0].
Stop traversal when the next chunk is null. Adds a regression test that fails
before this change (NPE) and passes after it.
* Refactor forEachWhile to use lambda in test
Refactor test method to use lambda expression.
---------
Co-authored-by: David Karnok <akarnokd@gmail.com>1 parent f08aa83 commit f995b98
2 files changed
Lines changed: 22 additions & 0 deletions
File tree
- src
- main/java/io/reactivex/rxjava4/internal/util
- test/java/io/reactivex/rxjava4/internal/util
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
178 | 181 | | |
179 | 182 | | |
180 | 183 | | |
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
239 | 258 | | |
0 commit comments