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

Missing reflection hints on controller parameters without annotations #29331

Closed
sdeleuze opened this issue Oct 17, 2022 · 2 comments
Closed

Missing reflection hints on controller parameters without annotations #29331

sdeleuze opened this issue Oct 17, 2022 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement

Comments

@sdeleuze
Copy link
Contributor

sdeleuze commented Oct 17, 2022

The @GetMapping endpoint specified in this comment triggers this error:

java.lang.IllegalStateException: No primary or single unique constructor found for class com.example.validation.NoteFilters
        at org.springframework.beans.BeanUtils.getResolvableConstructor(BeanUtils.java:266) ~[na:na]
        at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:219) ~[validation:6.0.0-SNAPSHOT]
        at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:85) ~[na:na]
        at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:147) ~[validation:6.0.0-SNAPSHOT]

ControllerMappingReflectiveProcessor should potentially be updated to add contructor hints on parameters without recognized annotation or with @ModelAttribute annotation.

@sdeleuze sdeleuze added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement theme: aot An issue related to Ahead-of-time processing labels Oct 17, 2022
@sdeleuze sdeleuze added this to the 6.0.0-RC2 milestone Oct 17, 2022
@sdeleuze sdeleuze self-assigned this Oct 17, 2022
@sdeleuze
Copy link
Contributor Author

sdeleuze commented Oct 19, 2022

The logic to support this use case is quite involved and the simplified one we have currently implemented in ControllerMappingReflectiveProcessor#registerParameterTypeHints won't be able to cover this usage of ServletModelAttributeMethodProcessor in catch-all mode configured in RequestMappingHandlerAdapter#getDefaultArgumentResolvers.

A solution discussed with @rstoyanchev yesterday and previously with @snicoll would be to reuse the logic from RequestMappingHandlerAdapter#getDefaultArgumentResolvers but we would have to provide different implementations for WebFlux versus WebMVC and adapt the hint after evaluating the argument resolver returned. Doable but involved so I move this issue in the 6.0.x bucket.

In the meantime, users can use @RegisterReflectionForBinding(Foo.class) (see related Javadoc) to add the relevant hints.

@sdeleuze sdeleuze modified the milestones: 6.0.0-RC2, 6.0.x Oct 19, 2022
@sdeleuze sdeleuze modified the milestones: 6.0.x, 6.1.x Feb 28, 2023
@sdeleuze
Copy link
Contributor Author

sdeleuze commented Dec 7, 2023

This issue is tightly related to #31765, we now document this native limitation in Spring Framework reference documentation and Spring Boot wiki. I tend to think the maintenance burden of implementing what is described in the comment above is not necessarily worth the effort, so I prefer to close this issue and reconsider only if there is a strong ask from various users.

Conceptually, native require to have a more explicit programming model, and asking native users to use the explicitly @ModelAttribute to infer related hints does not sound an unreasonable ask to me.

@sdeleuze sdeleuze closed this as not planned Won't fix, can't repro, duplicate, stale Dec 7, 2023
@sdeleuze sdeleuze removed this from the 6.1.x milestone Dec 7, 2023
@sdeleuze sdeleuze added the status: declined A suggestion or change that we don't feel we should currently apply label Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant