From bf80485cc3b6146421f2b1f305b80e37af4e7d33 Mon Sep 17 00:00:00 2001
From: Sam Brannen <104798+sbrannen@users.noreply.github.com>
Date: Sun, 15 Dec 2024 15:53:33 +0100
Subject: [PATCH] Clean up after deprecation of AsyncResult
See gh-33809
---
.../scheduling/annotation/AsyncResult.java | 21 ----------
.../annotation/AsyncExecutionTests.java | 39 ++++++++++++-------
2 files changed, 24 insertions(+), 36 deletions(-)
diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java
index f168677d08..85ba965e07 100644
--- a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java
+++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java
@@ -27,11 +27,6 @@ import org.springframework.lang.Nullable;
* A pass-through {@code Future} handle that can be used for method signatures
* which are declared with a {@code Future} return type for asynchronous execution.
*
- *
As of Spring 4.1, this class implements {@code ListenableFuture}, not just
- * plain {@link java.util.concurrent.Future}, along with the corresponding support
- * in {@code @Async} processing. As of 7.0, this will be turned back to a plain
- * {@code Future} in order to focus on compatibility with existing common usage.
- *
* @author Juergen Hoeller
* @author Rossen Stoyanchev
* @since 3.0
@@ -123,20 +118,4 @@ public class AsyncResult implements Future {
return new AsyncResult<>(null, ex);
}
- /**
- * Determine the exposed exception: either the cause of a given
- * {@link ExecutionException}, or the original exception as-is.
- * @param original the original as given to {@link #forExecutionException}
- * @return the exposed exception
- */
- private static Throwable exposedException(Throwable original) {
- if (original instanceof ExecutionException) {
- Throwable cause = original.getCause();
- if (cause != null) {
- return cause;
- }
- }
- return original;
- }
-
}
diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java
index c64a14d14a..470ec3af09 100644
--- a/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java
+++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java
@@ -82,17 +82,17 @@ class AsyncExecutionTests {
CompletableFuture completableFuture = asyncTest.returnSomethingCompletable(20);
assertThat(completableFuture.get()).isEqualTo("20");
- assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
- asyncTest.returnSomething(0).get())
- .withCauseInstanceOf(IllegalArgumentException.class);
+ assertThatExceptionOfType(ExecutionException.class)
+ .isThrownBy(() -> asyncTest.returnSomething(0).get())
+ .withCauseInstanceOf(IllegalArgumentException.class);
- assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
- asyncTest.returnSomething(-1).get())
- .withCauseInstanceOf(IOException.class);
+ assertThatExceptionOfType(ExecutionException.class)
+ .isThrownBy(() -> asyncTest.returnSomething(-1).get())
+ .withCauseInstanceOf(IOException.class);
- assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
- asyncTest.returnSomethingCompletable(0).get())
- .withCauseInstanceOf(IllegalArgumentException.class);
+ assertThatExceptionOfType(ExecutionException.class)
+ .isThrownBy(() -> asyncTest.returnSomethingCompletable(0).get())
+ .withCauseInstanceOf(IllegalArgumentException.class);
}
@Test
@@ -165,13 +165,13 @@ class AsyncExecutionTests {
CompletableFuture completableFuture = asyncTest.returnSomethingCompletable(20);
assertThat(completableFuture.get()).isEqualTo("20");
- assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
- asyncTest.returnSomething(0).get())
- .withCauseInstanceOf(IllegalArgumentException.class);
+ assertThatExceptionOfType(ExecutionException.class)
+ .isThrownBy(() -> asyncTest.returnSomething(0).get())
+ .withCauseInstanceOf(IllegalArgumentException.class);
- assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
- asyncTest.returnSomethingCompletable(0).get())
- .withCauseInstanceOf(IllegalArgumentException.class);
+ assertThatExceptionOfType(ExecutionException.class)
+ .isThrownBy(() -> asyncTest.returnSomethingCompletable(0).get())
+ .withCauseInstanceOf(IllegalArgumentException.class);
}
@Test
@@ -390,6 +390,7 @@ class AsyncExecutionTests {
}
@Async
+ @SuppressWarnings("deprecation")
public Future returnSomething(int i) {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
if (i == 0) {
@@ -435,12 +436,14 @@ class AsyncExecutionTests {
}
@MyAsync
+ @SuppressWarnings("deprecation")
public Future returnSomething(int i) {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
assertThat(Thread.currentThread().getName()).startsWith("e2-");
return new AsyncResult<>(Integer.toString(i));
}
+ @SuppressWarnings("deprecation")
public Future returnSomething2(int i) {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
assertThat(Thread.currentThread().getName()).startsWith("e0-");
@@ -467,6 +470,7 @@ class AsyncExecutionTests {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
}
+ @SuppressWarnings("deprecation")
public Future returnSomething(int i) {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
if (i == 0) {
@@ -507,6 +511,7 @@ class AsyncExecutionTests {
}
@Override
+ @SuppressWarnings("deprecation")
public Future returnSomething(int i) {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
return new AsyncResult<>(Integer.toString(i));
@@ -531,6 +536,7 @@ class AsyncExecutionTests {
}
@Override
+ @SuppressWarnings("deprecation")
public Future returnSomething(int i) {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
return new AsyncResult<>(Integer.toString(i));
@@ -542,6 +548,7 @@ class AsyncExecutionTests {
private final AsyncInterface proxy;
+ @SuppressWarnings("deprecation")
public DynamicAsyncInterfaceBean() {
ProxyFactory pf = new ProxyFactory(new HashMap<>());
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor((MethodInterceptor) invocation -> {
@@ -598,6 +605,7 @@ class AsyncExecutionTests {
}
@Override
+ @SuppressWarnings("deprecation")
public Future returnSomething(int i) {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
return new AsyncResult<>(Integer.toString(i));
@@ -609,6 +617,7 @@ class AsyncExecutionTests {
private final AsyncMethodsInterface proxy;
+ @SuppressWarnings("deprecation")
public DynamicAsyncMethodsInterfaceBean() {
ProxyFactory pf = new ProxyFactory(new HashMap<>());
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor((MethodInterceptor) invocation -> {