fix(java-client): guard against NPE in FutureGroup.waitAllComplete when future cause is null - #2410
Open
cauchy1988 wants to merge 1 commit into
Open
fix(java-client): guard against NPE in FutureGroup.waitAllComplete when future cause is null#2410cauchy1988 wants to merge 1 commit into
cauchy1988 wants to merge 1 commit into
Conversation
…en future cause is null `waitAllComplete` dereferenced `fu.cause()` to build the failure message, but a netty Future reports `cause() == null` not only on success but also while it is still incomplete (e.g. after `await` timed out without the future ever resolving). In that window `isSuccess()` is false yet `cause()` is null, so `cause().getMessage()` threw a NullPointerException, crashing the whole batch commit instead of reporting the single failed task. Guard the dereference and fall back to a placeholder message when cause is null. Add a regression test that mocks an incomplete Future to reproduce the NPE deterministically (verified: reverting the fix makes the new test fail with the exact NPE at FutureGroup.java:117, the location reported in the issue). Closes apache#2152
cauchy1988
force-pushed
the
fix/futuregroup-npe-2152
branch
from
June 18, 2026 02:48
29a7cbf to
17765d2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Closes #2152. When using batch APIs (
Batch.asyncCommit→FutureGroup.waitAllComplete, a.k.a.commitWaitAllComplete), aNullPointerExceptioncan occur intermittently.Root cause
FutureGroup.waitAllCompletebuilds the failure message by dereferencingfu.cause():A netty
Future.cause()returnsnullnot only on success, but also while the future is still incomplete. Ifawaittimes out before the future ever resolves,isSuccess()isfalse(so we enter theelsebranch) butcause()is stillnull— thuscause().getMessage()throws NPE, crashing the entire batch commit instead of reporting just the single failed task.The sibling method
waitAllCompleteOrOneFailis unaffected because it passesfu.cause()directly to thePExceptionconstructor, which toleratesnull.Fix
Guard the dereference and fall back to a placeholder message when
cause()isnull:This matches the fix suggested by the issue reporter.
Test
Added
TestFutureGroup.testWaitAllCompleteHandlesNullCause, which uses Mockito to mock an incomplete Future (await→false,isSuccess→false,cause→null) to reproduce the scenario deterministically, without relying on timing.Verified both directions:
TestFutureGrouppass.