Methods annotated with @Async must return either Future or void

This rule flags Java methods annotated with org.springframework.scheduling.annotation.Async that return types other than void, Future<t>, CompletableFuture<t> or ListenableFuture<t>.

In Spring Framework 6, these return type requirements are strictly enforced at runtime. Any @Async method returning a non-supported type will now throw an Exception.

The following example shows valid usage of methods that uses @Async with a compliant return type.


import org.springframework.scheduling.annotation.Async;
import java.util.concurrent.Future;
import java.util.concurrent.CompletableFuture;
import org.springframework.util.concurrent.ListenableFuture;

public class ValidAsyncMethods {
	
    @Async
    public void asyncVoid() {
    }
    @Async
    public Future<String> asyncFuture() {
        return null;
    }
    @Async
    public CompletableFuture<Integer> asyncCompletableFuture() {
        return null;
    }
    @Async
    public ListenableFuture<String> asyncListenableFuture() {
        return null;
    }
}

For more information, see the following resources: