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

NPE in MvcUriComponentsBuilder with no-arg target method on interface #30756

Closed
dkfellows opened this issue Jun 26, 2023 · 1 comment
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: regression A bug that is also a regression
Milestone

Comments

@dkfellows
Copy link

dkfellows commented Jun 26, 2023

Affects: 5.3.28 (maybe others as well)

Setup:

MyController is an interface annotated with @RequestMapping with a method, myMethod(), that takes no arguments and returns a ModelAndView.

@RequestMapping("/some/path")
public interface MyController {
    @GetMapping("myMethod")
    ModelAndView myMethod();
}

The code mentioned below runs in the context of the implementation of the controller.


Issue:

When we use MvcUriComponentsBuilder as in below (within the context of a current request, of course):

MyController controller = MvcUriComponentsBuilder.on(MyController.class);
URI uri = MvcUriComponentsBuilder.fromMethodCall(
        controller.myMethod()).build().toUri();

then we get a NullPointerException from inside fromMethodCall() because it is claiming that the list of arguments is null.

This definitely used to work! (Alas, we've not tried it for some number of patch releases, so I can't easily identify what release broke it.)

Critically, this doesn't affect any method that takes any arguments.

Some Analysis:

The relevant bit of stack trace:

java.lang.NullPointerException: null
        at org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.applyContributors(MvcUriComponentsBuilder.java:634) ~[spring-webmvc-5.3.28.jar!/:5.3.28]
        at org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.fromMethodInternal(MvcUriComponentsBuilder.java:552) ~[spring-webmvc-5.3.28.jar!/:5.3.28]
        at org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.fromMethodCall(MvcUriComponentsBuilder.java:320) ~[spring-webmvc-5.3.28.jar!/:5.3.28]
        at ...

It looks like something is setting the argument array in the MethodInvocationInfo to null instead of a zero-length object array (or maybe just isn't setting it and that's the default?) but the code to work with those things is getting rather deep for me. It's all in codegen and related.


More details:

We're using this approach to generate URIs that are used to implement calls that implement behaviour of controls in the web UI. It's a bit more wrapped inside our code, but I don't believe those bits of wrapping relate to the bug.

We worked around it by adding an ignorable ModelMap to all methods that had no other arguments (we can pass a null for it to the proxied call that generates the URI). That's fine as a workaround for us.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 26, 2023
@jhoeller
Copy link
Contributor

This looks like a regression caused by #29913, just affecting no-arg methods on interface-based proxies. We'll fix this for the upcoming 6.0.11 and 5.3.29 releases.

@jhoeller jhoeller added in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 26, 2023
@jhoeller jhoeller self-assigned this Jun 26, 2023
@jhoeller jhoeller added this to the 6.0.11 milestone Jun 26, 2023
@jhoeller jhoeller added the for: backport-to-5.3.x Marks an issue as a candidate for backport to 5.3.x label Jun 26, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.3.x Marks an issue as a candidate for backport to 5.3.x labels Jun 26, 2023
@jhoeller jhoeller changed the title NPE in MvcUriComponentsBuilder with no-arg target method NPE in MvcUriComponentsBuilder with no-arg target method on interface Jun 26, 2023
jhoeller added a commit that referenced this issue Jun 26, 2023
mdeinum pushed a commit to mdeinum/spring-framework that referenced this issue Jun 29, 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: backported An issue that has been backported to maintenance branches type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

3 participants