Skip to content

Commit 9fffb5b

Browse files
artembilanspring-builds
authored andcommitted
GH-9702: Add CheckedCallable.uncheckedCallable
Fixes: #9702 Issue link: #9702 The current `CheckedCallable.unchecked()` returns `Runnable`, which is not an expectation. * Deprecate `CheckedCallable.unchecked()` in favor of newly introduced `CheckedCallable.uncheckedCallable()`. We cannot call it `unchecked()` as well, since `Callable` after erasure becomes similar to class signature as `Runnable`. (cherry picked from commit 8c22bf6)
1 parent 1d66863 commit 9fffb5b

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

spring-integration-core/src/main/java/org/springframework/integration/util/CheckedCallable.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 the original author or authors.
2+
* Copyright 2023-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.integration.util;
1818

19+
import java.util.concurrent.Callable;
20+
1921
/**
2022
* A Callable-like interface which allows throwing any Throwable.
2123
* Checked exceptions are wrapped in an IllegalStateException.
@@ -32,10 +34,29 @@ public interface CheckedCallable<T, E extends Throwable> {
3234

3335
T call() throws E;
3436

37+
/**
38+
* Wrap the {@link #call()} into unchecked {@link Runnable} (by mistake).
39+
* Re-throw its exception wrapped with a {@link IllegalStateException}.
40+
* @return the Runnable (by mistake).
41+
* @deprecated since 6.3.7 in favor of {@link #uncheckedCallable()}.
42+
* Will be restored back, but with a proper {@link Callable<T>} return type.
43+
*/
44+
@Deprecated
3545
default Runnable unchecked() {
46+
return this::uncheckedCallable;
47+
}
48+
49+
/**
50+
* Wrap the {@link #call()} into unchecked {@link Callable<T>}.
51+
* Re-throw its exception wrapped with a {@link IllegalStateException}.
52+
* Will be replaced with a proper {@link #unchecked()} implementation in 6.5.
53+
* @return the unchecked {@link Callable<T>}.
54+
* @since 6.3.7
55+
*/
56+
default Callable<T> uncheckedCallable() {
3657
return () -> {
3758
try {
38-
call();
59+
return call();
3960
}
4061
catch (Throwable t) { // NOSONAR
4162
if (t instanceof RuntimeException runtimeException) { // NOSONAR

0 commit comments

Comments
 (0)