spring-projects / spring-projects/spring-framework

Cglib proxies created by MvcUriComponentsBuilder should be processed at build-time

Open
#29,500 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: web theme: aot type: enhancement
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

Affects: 6.0.0

I have a simple controller that goes like

    @PostMapping
    public ResponseEntity<?> insert(
            @RequestBody @Valid CustomerApiDTO customerDTO) {

        var customerEntity = customerMapper.map(customerDTO);

        customerRepository.saveAndFlush(customerEntity);

        var uri = MvcUriComponentsBuilder.fromMethodCall(
                MvcUriComponentsBuilder.on(CustomerApiController.class)
                        .findByCustomerNumber(customerDTO.getCustomerNumber())  
        ).build();
        return ResponseEntity.created(uri.toUri()).build(); 
    }

With AOT generating the proxy for the controller this fails with:

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
        at de.eiswind.training.spring.rest.customer.responseentity.CustomerApiController$$SpringCGLIB$$1.setCallbacks(<generated>)
        at org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder$ControllerMethodInvocationInterceptor.initProxy(MvcUriComponentsBuilder.java:814)
        at org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.controller(MvcUriComponentsBuilder.java:383)

Please let me know if I can provide any further help with this.

Please forgive: I am not sure where to file this issue as it goes with AOT.

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 MvcUriComponentsBuilder.controller and ControllerMethodInvocationInterceptor.initProxy in MvcUriComponentsBuilder.java, then trace how AOT-generated controller proxies are created. Reproduce the reported ArrayIndexOutOfBoundsException with fromMethodCall and verify that controller proxies work without the runtime callback mismatch. Add or update a regression test covering this AOT proxy path.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
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.