Why is this an issue?

The Spring framework provides the annotation Async to mark a method (or all methods of a type) as a candidate for asynchronous execution.

Asynchronous methods do not necessarily, by their nature, return the result of their calculation immediately. Hence, it is unexpected and in clear breach of the Async contract for such methods to have a return type that is neither void nor a Future type.

How to fix it

Use void as the return type if the method is not expected to return a result. Otherwise, a Future should be returned, allowing the caller to retrieve the result once it is ready. It is permitted to return more specific subtypes that inherit from Future.

Code examples

Noncompliant code example

@Async
public String asyncMethod() {
  ...
}

Compliant solution

@Async
public Future<String> asyncMethod() {
  ...
}

Alternatively, if the method does not need to return a result:

@Async
public void asyncMethod() {
  ...
}

Resources

Documentation