Skip to content

Commit

Permalink
Explicitly allow null into CompletableResultCode.failExceptionally() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
breedx-splk authored Dec 19, 2024
1 parent 40b74b0 commit c1b9ec7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ public CompletableResultCode fail() {
* 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);
}

Expand Down Expand Up @@ -160,7 +161,8 @@ public boolean isSuccess() {
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ void fail() throws InterruptedException {
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();
Expand Down

0 comments on commit c1b9ec7

Please sign in to comment.