Explicitly allow null into CompletableResultCode.failExceptionally() (#6963)

This commit is contained in:
jason plumb 2024-12-19 13:57:17 -08:00 committed by GitHub
parent 40b74b05e1
commit c1b9ec789c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View File

@ -123,9 +123,10 @@ public final class CompletableResultCode {
* Completes this {@link CompletableResultCode} unsuccessfully if it is not already completed,
* setting the {@link #getFailureThrowable() failure throwable} to {@code throwable}.
*
* @param throwable the {@code Throwable} that caused the failure, or {@code null}
* @since 1.41.0
*/
public CompletableResultCode failExceptionally(Throwable throwable) {
public CompletableResultCode failExceptionally(@Nullable Throwable throwable) {
return failInternal(throwable);
}
@ -160,7 +161,8 @@ public final class CompletableResultCode {
* via the {@link #whenComplete(Runnable)} method.
*
* @return the throwable if failed exceptionally, or null if: {@link #fail() failed without
* exception}, {@link #succeed() succeeded}, or not complete.g
* exception}, {@link #succeed() succeeded}, {@link #failExceptionally(Throwable)} with a null
* {@code throwable}, or not complete.
* @since 1.41.0
*/
@Nullable

View File

@ -79,6 +79,15 @@ class CompletableResultCodeTest {
assertThat(resultCode.isSuccess()).isFalse();
}
@Test
void failExceptionallyWithNull() {
CompletableResultCode resultCode = new CompletableResultCode();
CompletableResultCode result = resultCode.failExceptionally(null);
assertThat(result.isDone()).isTrue();
assertThat(result.isSuccess()).isFalse();
assertThat(result.getFailureThrowable()).isNull();
}
@Test
void whenDoublyCompleteSuccessfully() throws InterruptedException {
CompletableResultCode resultCode = new CompletableResultCode();