Skip to content

Commit c1b9ec7

Browse files
authored
Explicitly allow null into CompletableResultCode.failExceptionally() (#6963)
1 parent 40b74b0 commit c1b9ec7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

sdk/common/src/main/java/io/opentelemetry/sdk/common/CompletableResultCode.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@ public CompletableResultCode fail() {
123123
* Completes this {@link CompletableResultCode} unsuccessfully if it is not already completed,
124124
* setting the {@link #getFailureThrowable() failure throwable} to {@code throwable}.
125125
*
126+
* @param throwable the {@code Throwable} that caused the failure, or {@code null}
126127
* @since 1.41.0
127128
*/
128-
public CompletableResultCode failExceptionally(Throwable throwable) {
129+
public CompletableResultCode failExceptionally(@Nullable Throwable throwable) {
129130
return failInternal(throwable);
130131
}
131132

@@ -160,7 +161,8 @@ public boolean isSuccess() {
160161
* via the {@link #whenComplete(Runnable)} method.
161162
*
162163
* @return the throwable if failed exceptionally, or null if: {@link #fail() failed without
163-
* exception}, {@link #succeed() succeeded}, or not complete.g
164+
* exception}, {@link #succeed() succeeded}, {@link #failExceptionally(Throwable)} with a null
165+
* {@code throwable}, or not complete.
164166
* @since 1.41.0
165167
*/
166168
@Nullable

sdk/common/src/test/java/io/opentelemetry/sdk/common/CompletableResultCodeTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ void fail() throws InterruptedException {
7979
assertThat(resultCode.isSuccess()).isFalse();
8080
}
8181

82+
@Test
83+
void failExceptionallyWithNull() {
84+
CompletableResultCode resultCode = new CompletableResultCode();
85+
CompletableResultCode result = resultCode.failExceptionally(null);
86+
assertThat(result.isDone()).isTrue();
87+
assertThat(result.isSuccess()).isFalse();
88+
assertThat(result.getFailureThrowable()).isNull();
89+
}
90+
8291
@Test
8392
void whenDoublyCompleteSuccessfully() throws InterruptedException {
8493
CompletableResultCode resultCode = new CompletableResultCode();

0 commit comments

Comments
 (0)