Adapt no-arg value from interface-based InvocationHandler callback

Closes gh-30756
This commit is contained in:
Juergen Hoeller
2023-06-26 19:28:19 +02:00
parent 599ac58baa
commit b77d4d01c5
2 changed files with 45 additions and 5 deletions

View File

@@ -745,8 +745,8 @@ public class MvcUriComponentsBuilder {
@Override
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return intercept(proxy, method, args, null);
public Object invoke(Object proxy, Method method, @Nullable Object[] args) {
return intercept(proxy, method, (args != null ? args : new Object[0]), null);
}
@Override

View File

@@ -293,6 +293,14 @@ public class MvcUriComponentsBuilderTests {
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/input");
}
@Test
public void fromMethodCallOnSubclass() {
UriComponents uriComponents = fromMethodCall(on(ExtendedController.class).myMethod(null)).build();
assertThat(uriComponents.toUriString()).startsWith("http://localhost");
assertThat(uriComponents.toUriString()).endsWith("/extended/else");
}
@Test
public void fromMethodCallPlain() {
UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).myMethod(null)).build();
@@ -302,11 +310,27 @@ public class MvcUriComponentsBuilderTests {
}
@Test
public void fromMethodCallOnSubclass() {
UriComponents uriComponents = fromMethodCall(on(ExtendedController.class).myMethod(null)).build();
public void fromMethodCallPlainWithNoArguments() {
UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).myMethod()).build();
assertThat(uriComponents.toUriString()).startsWith("http://localhost");
assertThat(uriComponents.toUriString()).endsWith("/extended/else");
assertThat(uriComponents.toUriString()).endsWith("/something/noarg");
}
@Test
public void fromMethodCallPlainOnInterface() {
UriComponents uriComponents = fromMethodCall(on(ControllerInterface.class).myMethod(null)).build();
assertThat(uriComponents.toUriString()).startsWith("http://localhost");
assertThat(uriComponents.toUriString()).endsWith("/something/else");
}
@Test
public void fromMethodCallPlainWithNoArgumentsOnInterface() {
UriComponents uriComponents = fromMethodCall(on(ControllerInterface.class).myMethod()).build();
assertThat(uriComponents.toUriString()).startsWith("http://localhost");
assertThat(uriComponents.toUriString()).endsWith("/something/noarg");
}
@Test
@@ -575,6 +599,11 @@ public class MvcUriComponentsBuilderTests {
return null;
}
@RequestMapping("/noarg")
HttpEntity<Void> myMethod() {
return null;
}
@RequestMapping("/{id}/foo")
HttpEntity<Void> methodWithPathVariable(@PathVariable String id) {
return null;
@@ -616,6 +645,17 @@ public class MvcUriComponentsBuilderTests {
}
@RequestMapping("/something")
public interface ControllerInterface {
@RequestMapping("/else")
HttpEntity<Void> myMethod(@RequestBody Object payload);
@RequestMapping("/noarg")
HttpEntity<Void> myMethod();
}
@RequestMapping("/user/{userId}/contacts")
static class UserContactController {