cauchy1988 opened a new pull request, #2410:
URL: https://github.com/apache/incubator-pegasus/pull/2410
## Background
Closes #2152. When using batch APIs (`Batch.asyncCommit` →
`FutureGroup.waitAllComplete`, a.k.a. `commitWaitAllComplete`), a
`NullPointerException` can occur intermittently.
## Root cause
`FutureGroup.waitAllComplete` builds the failure message by dereferencing
`fu.cause()`:
```java
} else {
results.add(Pair.of(
new PException("async task #[" + i + "] await failed: " +
fu.cause().getMessage()),
null));
}
```
A netty `Future.cause()` returns `null` **not only on success**, but also
**while the future is still incomplete**. If `await` times out before the
future ever resolves, `isSuccess()` is `false` (so we enter the `else` branch)
but `cause()` is still `null` — thus `cause().getMessage()` throws NPE,
crashing the entire batch commit instead of reporting just the single failed
task.
The sibling method `waitAllCompleteOrOneFail` is unaffected because it
passes `fu.cause()` directly to the `PException` constructor, which tolerates
`null`.
## Fix
Guard the dereference and fall back to a placeholder message when `cause()`
is `null`:
```java
Throwable cause = fu.cause();
String causeMsg = cause != null ? cause.getMessage() : "unknown cause
(future not completed)";
results.add(Pair.of(new PException("async task #[" + i + "] await failed: "
+ causeMsg), null));
```
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:
- **With the fix**: all 3 tests in `TestFutureGroup` pass.
- **Without the fix** (temporarily reverted): the new test fails with the
exact NPE reported in the issue:
```
NullPointerException: Cannot invoke "Throwable.getMessage()" because the
return value of "io.netty.util.concurrent.Future.cause()" is null
at FutureGroup.waitAllComplete(FutureGroup.java:117)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]