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: * https://github.com/SpiNNakerManchester/JavaSpiNNaker/issues/915

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.

Comment From: jhoeller

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.