Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncExecution fails to detect the return type of an annotated method from an interface with a generic #33957

Conversation

anaconda875
Copy link

@anaconda875 anaconda875 commented Nov 25, 2024

The last param of AsyncExecutionAspectSupport.doSubmit is a return type, which can be get from the invocation. But in case of interface with paramter type like:

interface Service<O> {
  O doSomething();
}

class DefaultAsyncService implements Service<Future<String>> {
  @Override
  @Async
  public Future<String> doSomething() {
   return CompletableFuture.abc();
  }
}

@RestController
class Controller {
  @Autowire
  Service<Future<String>> service;

  @GetMapping
  public Future<String> api() {
    return service.doSomething();
  }
}

Return type retuned by invocation.getMethod().getReturnType() will be Object because we invoke doSomething by the interface, not by the impl.
My PR try to fix that

Verified

This commit was signed with the committer’s verified signature.
jmikola Jeremy Mikola
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 25, 2024
@snicoll
Copy link
Member

snicoll commented Nov 26, 2024

Can you please add a unit test that exercise the scenario you've described?

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Nov 26, 2024
@anaconda875
Copy link
Author

anaconda875 commented Nov 27, 2024

Can you please add a unit test that exercise the scenario you've described?

Hi @snicoll , you need a unit test which cover the fix/changes, or the unit test to reproduce the issue?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 27, 2024
@snicoll
Copy link
Member

snicoll commented Nov 27, 2024

Isn't that the same thing? I'd like that we see the change covered by an actual test that shows the behavior you've described is now working.

@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Nov 27, 2024
@anaconda875
Copy link
Author

Isn't that the same thing? I'd like that we see the change covered by an actual test that shows the behavior you've described is now working.

Ok I will add it soon. Thank you

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 27, 2024
@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Nov 27, 2024

Verified

This commit was signed with the committer’s verified signature.
jmikola Jeremy Mikola
…ted on interface
@anaconda875 anaconda875 changed the title Fix wrong return type when invoking Async-annotated Fix wrong return type when invoking Async-annotated method on interface Nov 27, 2024
@anaconda875
Copy link
Author

I added unit test

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 28, 2024
@snicoll snicoll requested a review from jhoeller December 4, 2024 11:51
@rstoyanchev rstoyanchev added the in: core Issues in core modules (aop, beans, core, context, expression) label Feb 3, 2025
@jhoeller
Copy link
Contributor

jhoeller commented Feb 4, 2025

Could we simply always use userMethod.getReturnType() instead of invocation.getMethod().getReturnType()?

@snicoll snicoll self-assigned this Feb 4, 2025
@snicoll snicoll added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Feb 4, 2025
@snicoll snicoll added this to the 6.2.3 milestone Feb 4, 2025
@snicoll snicoll changed the title Fix wrong return type when invoking Async-annotated method on interface AsyncExecution fails to detect the return type of an annotated method from an interface with a generic Feb 4, 2025
snicoll pushed a commit that referenced this pull request Feb 4, 2025

Verified

This commit was signed with the committer’s verified signature.
jmikola Jeremy Mikola
See gh-33957
@snicoll
Copy link
Member

snicoll commented Feb 4, 2025

@anaconda874 thanks very much for making your first contribution to Spring Framework.

@anaconda875

This comment was marked as resolved.

@snicoll

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants