Skip to content

[Banned, AI Slop, Undisclosed AI Use, Had to Manually Correct PR] Fix NullPointerException in AppendOnlyLinkedArrayList.forEachWhile on a full last chunk#8174

Merged
akarnokd merged 2 commits into
ReactiveX:4.xfrom
vasiliy-mikhailov:fix-appendonly-foreachwhile-npe
Jun 25, 2026

Conversation

@vasiliy-mikhailov

Copy link
Copy Markdown

When forEachWhile(S, BiPredicate) is called on an AppendOnlyLinkedArrayList whose last chunk is exactly full — i.e. the number of elements is a multiple of the chunk capacity — the next-chunk pointer stored at a[capacity] is still null (a new chunk is only allocated on the next add). After traversing the full chunk, a becomes null and the next loop iteration throws NullPointerException when reading a[0].

This only affects the BiPredicate overload; it stops the traversal when the next chunk is null.

Reproducer (capacity 2, two elements, predicate never terminates):

AppendOnlyLinkedArrayList<Integer> list = new AppendOnlyLinkedArrayList<>(2);
list.add(1);
list.add(2);
list.forEachWhile(null, (state, value) -> false); // NPE before this change

A regression test is added (MiscUtilTest.appendOnlyLinkedArrayListForEachWhileBiFullChunkNoNext) that fails before the change with NullPointerException and passes after it.

… 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.
@github-actions

Copy link
Copy Markdown

🐷 TruffleHog + Entropy Beauty Scan

Average entropy of changed code: 4.817 bits/char
Verdict: ⚠️ Consider review — entropy outside sweet spot

Changed files entropy:

src/main/java/io/reactivex/rxjava4/core/Observable.java: 4.759
src/main/java/io/reactivex/rxjava4/core/config/ObservableCombineLatestConfig.java: 4.814
src/test/java/io/reactivex/rxjava4/core/config/ObservableCombineLatestConfigTest.java: 4.996
src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableCombineLatestTest.java: 4.680
src/test/java/io/reactivex/rxjava4/validators/ParamValidationCheckerTest.java: 4.838

✅ No secrets or suspicious high-entropy strings found.

Mid-4 beauty heuristic in action — powered by our entropy chats! 😊

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.31%. Comparing base (67fd64f) to head (771e743).
⚠️ Report is 2 commits behind head on 4.x.

Additional details and impacted files
@@             Coverage Diff              @@
##                4.x    #8174      +/-   ##
============================================
- Coverage     98.34%   98.31%   -0.04%     
+ Complexity     6944     6933      -11     
============================================
  Files           782      784       +2     
  Lines         49057    48997      -60     
  Branches       6599     6597       -2     
============================================
- Hits          48246    48172      -74     
- Misses          622      627       +5     
- Partials        189      198       +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@akarnokd akarnokd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use lambdas.


list.forEachWhile(null, new BiPredicate<Object, Integer>() {
@Override
public boolean test(Object state, Integer value) throws Throwable {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use lambdas.

@akarnokd

Copy link
Copy Markdown
Member

@copilot can you update PR so that the test method uses a lambda instead of the anonymous inner class?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a NullPointerException in AppendOnlyLinkedArrayList.forEachWhile(S, BiPredicate) when the last chunk is exactly full (no next-chunk allocated yet), ensuring traversal stops cleanly instead of dereferencing a null next chunk.

Changes:

  • Add a null-next-chunk guard in AppendOnlyLinkedArrayList.forEachWhile(S, BiPredicate) to prevent NullPointerException on a full last chunk.
  • Add a regression test covering the “full last chunk, no next chunk” scenario for the BiPredicate overload.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/main/java/io/reactivex/rxjava4/internal/util/AppendOnlyLinkedArrayList.java Stops forEachWhile(S, BiPredicate) when the next chunk pointer is null after processing a full chunk.
src/test/java/io/reactivex/rxjava4/internal/util/MiscUtilTest.java Adds a regression test reproducing and asserting the fixed behavior for a full last chunk with no next chunk.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/test/java/io/reactivex/rxjava4/internal/util/MiscUtilTest.java Outdated
Refactor test method to use lambda expression.
@github-actions

Copy link
Copy Markdown

🐷 TruffleHog + Entropy Beauty Scan

Average entropy of changed code: 4.735 bits/char
Verdict: ⚠️ Consider review — entropy outside sweet spot

Changed files entropy:

src/main/java/io/reactivex/rxjava4/core/Flowable.java: 4.779
src/main/java/io/reactivex/rxjava4/core/Observable.java: 4.757
src/main/java/io/reactivex/rxjava4/core/config/CompletableConcatConfig.java: 4.771
src/main/java/io/reactivex/rxjava4/core/config/CompletableMergeConfig.java: 4.849
src/main/java/io/reactivex/rxjava4/core/config/FlatMapConfig.java: 4.869
src/main/java/io/reactivex/rxjava4/core/config/GenericConfig.java: 4.848
src/main/java/io/reactivex/rxjava4/core/config/MaybeConcatEagerConfig.java: 4.797
src/main/java/io/reactivex/rxjava4/core/config/MaybeMergeConfig.java: 4.876
src/main/java/io/reactivex/rxjava4/core/config/ObservableCombineLatestConfig.java: 4.820
src/main/java/io/reactivex/rxjava4/core/config/ObservableMergeConfig.java: 4.884
src/main/java/io/reactivex/rxjava4/core/config/ParallelSchedulerConfig.java: 4.724
src/main/java/io/reactivex/rxjava4/core/config/SingleConcatConfig.java: 4.773
src/main/java/io/reactivex/rxjava4/core/config/SingleConcatEagerConfig.java: 4.794
src/main/java/io/reactivex/rxjava4/core/config/SingleMergeConfig.java: 4.869
src/main/java/io/reactivex/rxjava4/observers/TestObserver.java: 4.609
src/main/java/io/reactivex/rxjava4/schedulers/Schedulers.java: 4.730
src/main/java/io/reactivex/rxjava4/subscribers/TestSubscriber.java: 4.602
src/test/java/io/reactivex/rxjava4/core/config/ObservableMergeConfigTest.java: 4.986
src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableDebounceTest.java: 4.750
src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableFlatMapTest.java: 4.594

✅ No secrets or suspicious high-entropy strings found.

Mid-4 beauty heuristic in action — powered by our entropy chats! 😊

@akarnokd akarnokd merged commit f995b98 into ReactiveX:4.x Jun 25, 2026
6 checks passed
@akarnokd

akarnokd commented Jun 25, 2026

Copy link
Copy Markdown
Member

After some discussion with Grok, we came to the conclusion this PR is a result of an AI agent and as such is not disclosed.

In addition, your AI failed to respond to correction requests, which made me fix your AI's bad output.

We clearly declared our stance on AI contributions. You violated them.

You are hereby banned from this repository and will shame you for your failure too.

@akarnokd akarnokd changed the title Fix NullPointerException in AppendOnlyLinkedArrayList.forEachWhile on a full last chunk [Banned, AI Slop, Undisclosed AI Use, Manually Corrected] Fix NullPointerException in AppendOnlyLinkedArrayList.forEachWhile on a full last chunk Jun 25, 2026
@akarnokd akarnokd changed the title [Banned, AI Slop, Undisclosed AI Use, Manually Corrected] Fix NullPointerException in AppendOnlyLinkedArrayList.forEachWhile on a full last chunk [Banned, AI Slop, Undisclosed AI Use, Had to Manually Correct PR] Fix NullPointerException in AppendOnlyLinkedArrayList.forEachWhile on a full last chunk Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants