Skip to content

Commit 14da1ac

Browse files
committed
Adapt no-arg value from interface-based InvocationHandler callback
Closes gh-30756 (cherry picked from commit b77d4d0)
1 parent ce97342 commit 14da1ac

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,8 @@ public Object intercept(@Nullable Object obj, Method method, Object[] args, @Nul
742742

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

749749
@Override

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ public void fromMethodNameWithMetaAnnotation() {
287287
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/input");
288288
}
289289

290+
@Test
291+
public void fromMethodCallOnSubclass() {
292+
UriComponents uriComponents = fromMethodCall(on(ExtendedController.class).myMethod(null)).build();
293+
294+
assertThat(uriComponents.toUriString()).startsWith("http://localhost");
295+
assertThat(uriComponents.toUriString()).endsWith("/extended/else");
296+
}
297+
290298
@Test
291299
public void fromMethodCallPlain() {
292300
UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).myMethod(null)).build();
@@ -296,11 +304,27 @@ public void fromMethodCallPlain() {
296304
}
297305

298306
@Test
299-
public void fromMethodCallOnSubclass() {
300-
UriComponents uriComponents = fromMethodCall(on(ExtendedController.class).myMethod(null)).build();
307+
public void fromMethodCallPlainWithNoArguments() {
308+
UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).myMethod()).build();
301309

302310
assertThat(uriComponents.toUriString()).startsWith("http://localhost");
303-
assertThat(uriComponents.toUriString()).endsWith("/extended/else");
311+
assertThat(uriComponents.toUriString()).endsWith("/something/noarg");
312+
}
313+
314+
@Test
315+
public void fromMethodCallPlainOnInterface() {
316+
UriComponents uriComponents = fromMethodCall(on(ControllerInterface.class).myMethod(null)).build();
317+
318+
assertThat(uriComponents.toUriString()).startsWith("http://localhost");
319+
assertThat(uriComponents.toUriString()).endsWith("/something/else");
320+
}
321+
322+
@Test
323+
public void fromMethodCallPlainWithNoArgumentsOnInterface() {
324+
UriComponents uriComponents = fromMethodCall(on(ControllerInterface.class).myMethod()).build();
325+
326+
assertThat(uriComponents.toUriString()).startsWith("http://localhost");
327+
assertThat(uriComponents.toUriString()).endsWith("/something/noarg");
304328
}
305329

306330
@Test
@@ -553,6 +577,11 @@ HttpEntity<Void> myMethod(@RequestBody Object payload) {
553577
return null;
554578
}
555579

580+
@RequestMapping("/noarg")
581+
HttpEntity<Void> myMethod() {
582+
return null;
583+
}
584+
556585
@RequestMapping("/{id}/foo")
557586
HttpEntity<Void> methodWithPathVariable(@PathVariable String id) {
558587
return null;
@@ -594,6 +623,17 @@ static class ExtendedController extends ControllerWithMethods {
594623
}
595624

596625

626+
@RequestMapping("/something")
627+
public interface ControllerInterface {
628+
629+
@RequestMapping("/else")
630+
HttpEntity<Void> myMethod(@RequestBody Object payload);
631+
632+
@RequestMapping("/noarg")
633+
HttpEntity<Void> myMethod();
634+
}
635+
636+
597637
@RequestMapping("/user/{userId}/contacts")
598638
static class UserContactController {
599639

0 commit comments

Comments
 (0)