Skip to content

Commit bf80485

Browse files
committed
Clean up after deprecation of AsyncResult
See gh-33809
1 parent 8a8df90 commit bf80485

File tree

2 files changed

+24
-36
lines changed

2 files changed

+24
-36
lines changed

spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java

-21
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727
* A pass-through {@code Future} handle that can be used for method signatures
2828
* which are declared with a {@code Future} return type for asynchronous execution.
2929
*
30-
* <p>As of Spring 4.1, this class implements {@code ListenableFuture}, not just
31-
* plain {@link java.util.concurrent.Future}, along with the corresponding support
32-
* in {@code @Async} processing. As of 7.0, this will be turned back to a plain
33-
* {@code Future} in order to focus on compatibility with existing common usage.
34-
*
3530
* @author Juergen Hoeller
3631
* @author Rossen Stoyanchev
3732
* @since 3.0
@@ -123,20 +118,4 @@ public static <V> Future<V> forExecutionException(Throwable ex) {
123118
return new AsyncResult<>(null, ex);
124119
}
125120

126-
/**
127-
* Determine the exposed exception: either the cause of a given
128-
* {@link ExecutionException}, or the original exception as-is.
129-
* @param original the original as given to {@link #forExecutionException}
130-
* @return the exposed exception
131-
*/
132-
private static Throwable exposedException(Throwable original) {
133-
if (original instanceof ExecutionException) {
134-
Throwable cause = original.getCause();
135-
if (cause != null) {
136-
return cause;
137-
}
138-
}
139-
return original;
140-
}
141-
142121
}

spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java

+24-15
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ void asyncMethods() throws Exception {
8282
CompletableFuture<String> completableFuture = asyncTest.returnSomethingCompletable(20);
8383
assertThat(completableFuture.get()).isEqualTo("20");
8484

85-
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
86-
asyncTest.returnSomething(0).get())
87-
.withCauseInstanceOf(IllegalArgumentException.class);
85+
assertThatExceptionOfType(ExecutionException.class)
86+
.isThrownBy(() -> asyncTest.returnSomething(0).get())
87+
.withCauseInstanceOf(IllegalArgumentException.class);
8888

89-
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
90-
asyncTest.returnSomething(-1).get())
91-
.withCauseInstanceOf(IOException.class);
89+
assertThatExceptionOfType(ExecutionException.class)
90+
.isThrownBy(() -> asyncTest.returnSomething(-1).get())
91+
.withCauseInstanceOf(IOException.class);
9292

93-
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
94-
asyncTest.returnSomethingCompletable(0).get())
95-
.withCauseInstanceOf(IllegalArgumentException.class);
93+
assertThatExceptionOfType(ExecutionException.class)
94+
.isThrownBy(() -> asyncTest.returnSomethingCompletable(0).get())
95+
.withCauseInstanceOf(IllegalArgumentException.class);
9696
}
9797

9898
@Test
@@ -165,13 +165,13 @@ void asyncClass() throws Exception {
165165
CompletableFuture<String> completableFuture = asyncTest.returnSomethingCompletable(20);
166166
assertThat(completableFuture.get()).isEqualTo("20");
167167

168-
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
169-
asyncTest.returnSomething(0).get())
170-
.withCauseInstanceOf(IllegalArgumentException.class);
168+
assertThatExceptionOfType(ExecutionException.class)
169+
.isThrownBy(() -> asyncTest.returnSomething(0).get())
170+
.withCauseInstanceOf(IllegalArgumentException.class);
171171

172-
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
173-
asyncTest.returnSomethingCompletable(0).get())
174-
.withCauseInstanceOf(IllegalArgumentException.class);
172+
assertThatExceptionOfType(ExecutionException.class)
173+
.isThrownBy(() -> asyncTest.returnSomethingCompletable(0).get())
174+
.withCauseInstanceOf(IllegalArgumentException.class);
175175
}
176176

177177
@Test
@@ -390,6 +390,7 @@ public void doSomething(int i) {
390390
}
391391

392392
@Async
393+
@SuppressWarnings("deprecation")
393394
public Future<String> returnSomething(int i) {
394395
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
395396
if (i == 0) {
@@ -435,12 +436,14 @@ public void doSomething(int i) {
435436
}
436437

437438
@MyAsync
439+
@SuppressWarnings("deprecation")
438440
public Future<String> returnSomething(int i) {
439441
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
440442
assertThat(Thread.currentThread().getName()).startsWith("e2-");
441443
return new AsyncResult<>(Integer.toString(i));
442444
}
443445

446+
@SuppressWarnings("deprecation")
444447
public Future<String> returnSomething2(int i) {
445448
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
446449
assertThat(Thread.currentThread().getName()).startsWith("e0-");
@@ -467,6 +470,7 @@ public void doSomething(int i) {
467470
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
468471
}
469472

473+
@SuppressWarnings("deprecation")
470474
public Future<String> returnSomething(int i) {
471475
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
472476
if (i == 0) {
@@ -507,6 +511,7 @@ public void doSomething(int i) {
507511
}
508512

509513
@Override
514+
@SuppressWarnings("deprecation")
510515
public Future<String> returnSomething(int i) {
511516
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
512517
return new AsyncResult<>(Integer.toString(i));
@@ -531,6 +536,7 @@ public void doSomething(int i) {
531536
}
532537

533538
@Override
539+
@SuppressWarnings("deprecation")
534540
public Future<String> returnSomething(int i) {
535541
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
536542
return new AsyncResult<>(Integer.toString(i));
@@ -542,6 +548,7 @@ public static class DynamicAsyncInterfaceBean implements FactoryBean<AsyncInterf
542548

543549
private final AsyncInterface proxy;
544550

551+
@SuppressWarnings("deprecation")
545552
public DynamicAsyncInterfaceBean() {
546553
ProxyFactory pf = new ProxyFactory(new HashMap<>());
547554
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor((MethodInterceptor) invocation -> {
@@ -598,6 +605,7 @@ public void doSomething(int i) {
598605
}
599606

600607
@Override
608+
@SuppressWarnings("deprecation")
601609
public Future<String> returnSomething(int i) {
602610
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
603611
return new AsyncResult<>(Integer.toString(i));
@@ -609,6 +617,7 @@ public static class DynamicAsyncMethodsInterfaceBean implements FactoryBean<Asyn
609617

610618
private final AsyncMethodsInterface proxy;
611619

620+
@SuppressWarnings("deprecation")
612621
public DynamicAsyncMethodsInterfaceBean() {
613622
ProxyFactory pf = new ProxyFactory(new HashMap<>());
614623
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor((MethodInterceptor) invocation -> {

0 commit comments

Comments
 (0)