spring-projects / spring-projects/spring-framework

AspectJ around aspect called twice when using a Mockito Spy

Open
#24,046 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: core type: bug
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

Spring Boot 2.2.0.RELEASE

Using @Async returning a Future cannot be canceled if the @Async method is called from a @SpyBean.

From debugging, it seems the @Async aspect is called twice, first before mockito handling method call then after Mockito calls method so the returned Future is invalid.

Sample project: https://github.com/cdalexndr/spring-boot-issue-18771

Just run gradlew test

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked sample project and run gradlew test to reproduce the failure. Trace the interaction between @Async, @SpyBean, Mockito handling, and the AspectJ aspect; done means the aspect is not applied twice and the returned Future can be canceled.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
backend, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.