A method that Spring calls has a signature that Spring rejects or cannot use

tx0/java:spring-callback-shapedefaulterrorbug

What it finds

Spring calls some annotated methods itself and expects a fixed shape: a @Scheduled method takes no arguments, an @EventListener takes at most the event, an @InitBinder method returns void, and an @Async method returns void or a Future, since the caller gets its result only through the future. Other shapes fail when the application starts, or lose the result, as the Spring documentation of each annotation says.

Reported is a @Scheduled method with parameters, an @EventListener with more than one, an @InitBinder method that returns a value, and an @Async method whose return type is neither void nor a Future, CompletableFuture, CompletionStage or ListenableFuture.

From the rule's source, spring_handler_signature.rs.

Example from the rule's tests
import java.util.concurrent.CompletableFuture;import org.springframework.context.event.EventListener;import org.springframework.scheduling.annotation.Async;import org.springframework.scheduling.annotation.Scheduled;import org.springframework.web.bind.annotation.InitBinder; class Jobs {  @Scheduled(fixedRate = 1000)  void tick(int count) {}tx0 reports: without arguments   @Scheduled(fixedRate = 1000)  void run() {}   @EventListener  void on(Object event, String extra) {}tx0 reports: at most the event   @InitBinder  boolean bind(Object binder) {tx0 reports: must return void    return true;  }   @Async  String load() {tx0 reports: only through a Future    return "";  }   @Async  CompletableFuture<String> fetch() {    return null;  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/java:spring-callback-shape" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:spring-callback-shape] reason="..."

tx0 explain tx0/java:spring-callback-shape shows the same in the terminal. Found a false positive? Report it.