Skip to content

Commit 9e3371e

Browse files
committed
Mark ListenableFuture as deprecated for removal
Closes gh-33808
1 parent c2c6bb2 commit 9e3371e

File tree

53 files changed

+209
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+209
-218
lines changed

spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-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.
@@ -281,8 +281,8 @@ protected Executor getDefaultExecutor(@Nullable BeanFactory beanFactory) {
281281
* @param returnType the declared return type (potentially a {@link Future} variant)
282282
* @return the execution result (potentially a corresponding {@link Future} handle)
283283
*/
284+
@SuppressWarnings("removal")
284285
@Nullable
285-
@SuppressWarnings("deprecation")
286286
protected Object doSubmit(Callable<Object> task, AsyncTaskExecutor executor, Class<?> returnType) {
287287
if (CompletableFuture.class.isAssignableFrom(returnType)) {
288288
return executor.submitCompletable(task);

spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleThreadPoolTaskExecutor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-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.
@@ -47,7 +47,7 @@
4747
* @see org.springframework.core.task.TaskExecutor
4848
* @see SchedulerFactoryBean#setTaskExecutor
4949
*/
50-
@SuppressWarnings("deprecation")
50+
@SuppressWarnings("removal")
5151
public class SimpleThreadPoolTaskExecutor extends SimpleThreadPool
5252
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, InitializingBean, DisposableBean {
5353

spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ protected Object[] resolveArguments(ApplicationEvent event) {
310310
return new Object[] {event};
311311
}
312312

313-
@SuppressWarnings({"deprecation", "unchecked"})
313+
@SuppressWarnings({"removal", "unchecked"})
314314
protected void handleResult(Object result) {
315315
if (reactiveStreamsPresent && new ReactiveResultHandler().subscribeToPublisher(result)) {
316316
if (logger.isTraceEnabled()) {

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-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.
@@ -31,12 +31,10 @@
3131
* A pass-through {@code Future} handle that can be used for method signatures
3232
* which are declared with a {@code Future} return type for asynchronous execution.
3333
*
34-
* <p>As of Spring 4.1, this class implements {@link ListenableFuture}, not just
34+
* <p>As of Spring 4.1, this class implements {@code ListenableFuture}, not just
3535
* plain {@link java.util.concurrent.Future}, along with the corresponding support
36-
* in {@code @Async} processing.
37-
*
38-
* <p>As of Spring 4.2, this class also supports passing execution exceptions back
39-
* to the caller.
36+
* in {@code @Async} processing. As of 7.0, this will be turned back to a plain
37+
* {@code Future} in order to focus on compatibility with existing common usage.
4038
*
4139
* @author Juergen Hoeller
4240
* @author Rossen Stoyanchev
@@ -48,6 +46,7 @@
4846
* @deprecated as of 6.0, in favor of {@link CompletableFuture}
4947
*/
5048
@Deprecated(since = "6.0")
49+
@SuppressWarnings("removal")
5150
public class AsyncResult<V> implements ListenableFuture<V> {
5251

5352
@Nullable
@@ -145,7 +144,7 @@ public CompletableFuture<V> completable() {
145144
* @since 4.2
146145
* @see Future#get()
147146
*/
148-
public static <V> ListenableFuture<V> forValue(V value) {
147+
public static <V> org.springframework.util.concurrent.ListenableFuture<V> forValue(V value) {
149148
return new AsyncResult<>(value, null);
150149
}
151150

@@ -157,7 +156,7 @@ public static <V> ListenableFuture<V> forValue(V value) {
157156
* @since 4.2
158157
* @see ExecutionException
159158
*/
160-
public static <V> ListenableFuture<V> forExecutionException(Throwable ex) {
159+
public static <V> org.springframework.util.concurrent.ListenableFuture<V> forExecutionException(Throwable ex) {
161160
return new AsyncResult<>(null, ex);
162161
}
163162

spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
* @see DefaultManagedTaskExecutor
6363
* @see ThreadPoolTaskExecutor
6464
*/
65-
@SuppressWarnings("deprecation")
65+
@SuppressWarnings("removal")
6666
public class ConcurrentTaskExecutor implements AsyncListenableTaskExecutor, SchedulingTaskExecutor {
6767

6868
private static final Executor STUB_EXECUTOR = (task -> {

spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.springframework.util.Assert;
4242
import org.springframework.util.ClassUtils;
4343
import org.springframework.util.ErrorHandler;
44-
import org.springframework.util.concurrent.ListenableFuture;
4544

4645
/**
4746
* Adapter that takes a {@code java.util.concurrent.ScheduledExecutorService} and
@@ -219,15 +218,15 @@ public <T> Future<T> submit(Callable<T> task) {
219218
return super.submit(new DelegatingErrorHandlingCallable<>(task, this.errorHandler));
220219
}
221220

222-
@SuppressWarnings("deprecation")
221+
@SuppressWarnings("removal")
223222
@Override
224-
public ListenableFuture<?> submitListenable(Runnable task) {
223+
public org.springframework.util.concurrent.ListenableFuture<?> submitListenable(Runnable task) {
225224
return super.submitListenable(TaskUtils.decorateTaskWithErrorHandler(task, this.errorHandler, false));
226225
}
227226

228-
@SuppressWarnings("deprecation")
227+
@SuppressWarnings("removal")
229228
@Override
230-
public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
229+
public <T> org.springframework.util.concurrent.ListenableFuture<T> submitListenable(Callable<T> task) {
231230
return super.submitListenable(new DelegatingErrorHandlingCallable<>(task, this.errorHandler));
232231
}
233232

spring-context/src/main/java/org/springframework/scheduling/concurrent/SimpleAsyncTaskScheduler.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.springframework.scheduling.support.TaskUtils;
4545
import org.springframework.util.Assert;
4646
import org.springframework.util.ErrorHandler;
47-
import org.springframework.util.concurrent.ListenableFuture;
4847

4948
/**
5049
* A simple implementation of Spring's {@link TaskScheduler} interface, using
@@ -270,15 +269,15 @@ public <T> Future<T> submit(Callable<T> task) {
270269
return super.submit(new DelegatingErrorHandlingCallable<>(task, this.errorHandler));
271270
}
272271

273-
@SuppressWarnings("deprecation")
272+
@SuppressWarnings("removal")
274273
@Override
275-
public ListenableFuture<?> submitListenable(Runnable task) {
274+
public org.springframework.util.concurrent.ListenableFuture<?> submitListenable(Runnable task) {
276275
return super.submitListenable(TaskUtils.decorateTaskWithErrorHandler(task, this.errorHandler, false));
277276
}
278277

279-
@SuppressWarnings("deprecation")
278+
@SuppressWarnings("removal")
280279
@Override
281-
public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
280+
public <T> org.springframework.util.concurrent.ListenableFuture<T> submitListenable(Callable<T> task) {
282281
return super.submitListenable(new DelegatingErrorHandlingCallable<>(task, this.errorHandler));
283282
}
284283

spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
* @see ThreadPoolExecutorFactoryBean
8181
* @see ConcurrentTaskExecutor
8282
*/
83-
@SuppressWarnings({"serial", "deprecation"})
83+
@SuppressWarnings({"serial", "removal"})
8484
public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
8585
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor {
8686

spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
* @see ThreadPoolTaskExecutor
7575
* @see SimpleAsyncTaskScheduler
7676
*/
77-
@SuppressWarnings({"serial", "deprecation"})
77+
@SuppressWarnings({"serial", "removal"})
7878
public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
7979
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, TaskScheduler {
8080

spring-context/src/test/java/example/scannable/AutowiredQualifierFooService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-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,7 @@
1616

1717
package example.scannable;
1818

19+
import java.util.concurrent.CompletableFuture;
1920
import java.util.concurrent.Future;
2021

2122
import jakarta.annotation.PostConstruct;
@@ -51,9 +52,8 @@ public String foo(int id) {
5152
}
5253

5354
@Override
54-
@SuppressWarnings("deprecation")
5555
public Future<String> asyncFoo(int id) {
56-
return new org.springframework.scheduling.annotation.AsyncResult<>(this.fooDao.findFoo(id));
56+
return CompletableFuture.completedFuture(this.fooDao.findFoo(id));
5757
}
5858

5959
@Override

spring-context/src/test/java/example/scannable/FooServiceImpl.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-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.
@@ -18,6 +18,7 @@
1818

1919
import java.util.Comparator;
2020
import java.util.List;
21+
import java.util.concurrent.CompletableFuture;
2122
import java.util.concurrent.Future;
2223

2324
import jakarta.annotation.PostConstruct;
@@ -91,10 +92,9 @@ public String lookupFoo(int id) {
9192
}
9293

9394
@Override
94-
@SuppressWarnings("deprecation")
9595
public Future<String> asyncFoo(int id) {
9696
Assert.state(ServiceInvocationCounter.getThreadLocalCount() != null, "Thread-local counter not exposed");
97-
return new org.springframework.scheduling.annotation.AsyncResult<>(fooDao().findFoo(id));
97+
return CompletableFuture.completedFuture(fooDao().findFoo(id));
9898
}
9999

100100
@Override

spring-context/src/test/java/example/scannable/ScopedProxyTestBean.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-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,7 @@
1616

1717
package example.scannable;
1818

19+
import java.util.concurrent.CompletableFuture;
1920
import java.util.concurrent.Future;
2021

2122
import org.springframework.context.annotation.Scope;
@@ -33,9 +34,8 @@ public String foo(int id) {
3334
}
3435

3536
@Override
36-
@SuppressWarnings("deprecation")
3737
public Future<String> asyncFoo(int id) {
38-
return new org.springframework.scheduling.annotation.AsyncResult<>("bar");
38+
return CompletableFuture.completedFuture("bar");
3939
}
4040

4141
@Override

spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ void collectionReplyNullValue() {
280280
}
281281

282282
@Test
283-
@SuppressWarnings("deprecation")
283+
@SuppressWarnings("removal")
284284
void listenableFutureReply() {
285285
load(TestEventListener.class, ReplyEventListener.class);
286286
org.springframework.util.concurrent.SettableListenableFuture<String> future =

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
class AsyncResultTests {
3333

3434
@Test
35-
@SuppressWarnings("deprecation")
35+
@SuppressWarnings("removal")
3636
public void asyncResultWithCallbackAndValue() throws Exception {
3737
String value = "val";
3838
final Set<String> values = new HashSet<>(1);
@@ -54,7 +54,7 @@ public void onFailure(Throwable ex) {
5454
}
5555

5656
@Test
57-
@SuppressWarnings("deprecation")
57+
@SuppressWarnings("removal")
5858
public void asyncResultWithCallbackAndException() {
5959
IOException ex = new IOException();
6060
final Set<Throwable> values = new HashSet<>(1);
@@ -79,7 +79,7 @@ public void onFailure(Throwable ex) {
7979
}
8080

8181
@Test
82-
@SuppressWarnings("deprecation")
82+
@SuppressWarnings("removal")
8383
public void asyncResultWithSeparateCallbacksAndValue() throws Exception {
8484
String value = "val";
8585
final Set<String> values = new HashSet<>(1);
@@ -92,7 +92,7 @@ public void asyncResultWithSeparateCallbacksAndValue() throws Exception {
9292
}
9393

9494
@Test
95-
@SuppressWarnings("deprecation")
95+
@SuppressWarnings("removal")
9696
public void asyncResultWithSeparateCallbacksAndException() {
9797
IOException ex = new IOException();
9898
final Set<Throwable> values = new HashSet<>(1);

spring-core/src/main/java/org/springframework/core/task/AsyncListenableTaskExecutor.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-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.
@@ -18,20 +18,18 @@
1818

1919
import java.util.concurrent.Callable;
2020

21-
import org.springframework.util.concurrent.ListenableFuture;
22-
2321
/**
2422
* Extension of the {@link AsyncTaskExecutor} interface, adding the capability to submit
25-
* tasks for {@link ListenableFuture ListenableFutures}.
23+
* tasks for {@code ListenableFutures}.
2624
*
2725
* @author Arjen Poutsma
2826
* @since 4.0
29-
* @see ListenableFuture
3027
* @deprecated as of 6.0, in favor of
3128
* {@link AsyncTaskExecutor#submitCompletable(Runnable)} and
3229
* {@link AsyncTaskExecutor#submitCompletable(Callable)}
3330
*/
34-
@Deprecated(since = "6.0")
31+
@Deprecated(since = "6.0", forRemoval = true)
32+
@SuppressWarnings("removal")
3533
public interface AsyncListenableTaskExecutor extends AsyncTaskExecutor {
3634

3735
/**
@@ -42,8 +40,8 @@ public interface AsyncListenableTaskExecutor extends AsyncTaskExecutor {
4240
* @throws TaskRejectedException if the given task was not accepted
4341
* @deprecated in favor of {@link AsyncTaskExecutor#submitCompletable(Runnable)}
4442
*/
45-
@Deprecated
46-
ListenableFuture<?> submitListenable(Runnable task);
43+
@Deprecated(since = "6.0", forRemoval = true)
44+
org.springframework.util.concurrent.ListenableFuture<?> submitListenable(Runnable task);
4745

4846
/**
4947
* Submit a {@code Callable} task for execution, receiving a {@code ListenableFuture}
@@ -54,7 +52,7 @@ public interface AsyncListenableTaskExecutor extends AsyncTaskExecutor {
5452
* @throws TaskRejectedException if the given task was not accepted
5553
* @deprecated in favor of {@link AsyncTaskExecutor#submitCompletable(Callable)}
5654
*/
57-
@Deprecated
58-
<T> ListenableFuture<T> submitListenable(Callable<T> task);
55+
@Deprecated(since = "6.0", forRemoval = true)
56+
<T> org.springframework.util.concurrent.ListenableFuture<T> submitListenable(Callable<T> task);
5957

6058
}

spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* @see org.springframework.scheduling.concurrent.SimpleAsyncTaskScheduler
5959
* @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
6060
*/
61-
@SuppressWarnings({"serial", "deprecation"})
61+
@SuppressWarnings({"serial", "removal"})
6262
public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
6363
implements AsyncListenableTaskExecutor, Serializable, AutoCloseable {
6464

spring-core/src/main/java/org/springframework/core/task/support/TaskExecutorAdapter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-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.
@@ -43,7 +43,7 @@
4343
* @see java.util.concurrent.ExecutorService
4444
* @see java.util.concurrent.Executors
4545
*/
46-
@SuppressWarnings("deprecation")
46+
@SuppressWarnings("removal")
4747
public class TaskExecutorAdapter implements AsyncListenableTaskExecutor {
4848

4949
private final Executor concurrentExecutor;

spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-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.
@@ -32,7 +32,8 @@
3232
* @param <T> the result type returned by this Future's {@code get} method
3333
* @deprecated as of 6.0, with no concrete replacement
3434
*/
35-
@Deprecated(since = "6.0")
35+
@Deprecated(since = "6.0", forRemoval = true)
36+
@SuppressWarnings("removal")
3637
public class CompletableToListenableFutureAdapter<T> implements ListenableFuture<T> {
3738

3839
private final CompletableFuture<T> completableFuture;

0 commit comments

Comments
 (0)