spring-projects / spring-projects/spring-hateoas
Breaking change in semantics of `WebMvcLinkBuilder.linkTo(Class<?>, Method, Object…)` in 1.3.4
@odrotbohm is already working on this.
Since Nov 22, 2021.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
When upgrading from Spring Boot 2.5.4 to 2.5.6, the version of Spring HATEOAS pulled in changes from 1.3.3 to 1.3.5. This broke our code using the WebMvcLinkBuilder method:
public static WebMvcLinkBuilder linkTo(Class<?> controller, Method method, Object... parameters) {
As can be seen below, the changes introduced in 1.3.4 are not backwards compatible with 1.3.3. The 1.3.3 version of the method only expects the URL template variables to be given, whereas starting from 1.3.4 is expecting all parameters from the actual controller method.
1.3.3:
public static WebMvcLinkBuilder linkTo(Class<?> controller, Method method, Object... parameters) {
Assert.notNull(controller, "Controller type must not be null!");
Assert.notNull(method, "Method must not be null!");
String mapping = SpringAffordanceBuilder.DISCOVERER.getMapping(controller, method);
UriTemplate template = UriTemplateFactory.templateFor(mapping);
URI uri = template.expand(parameters);
return new WebMvcLinkBuilder(UriComponentsBuilderFactory.getComponents()).slash(uri);
}
1.3.4:
public static WebMvcLinkBuilder linkTo(Class<?> controller, Method method, Object... parameters) {
Assert.notNull(controller, "Controller type must not be null!");
Assert.notNull(method, "Method must not be null!");
Assert.notNull(parameters, "Parameters must not be null!");
return linkTo(DummyInvocationUtils.getLastInvocationAware(controller, method, parameters));
}
1.3.5:
public static WebMvcLinkBuilder linkTo(Class<?> controller, Method method, Object... parameters) {
Assert.notNull(controller, "Controller type must not be null!");
Assert.notNull(method, "Method must not be null!");
Assert.notNull(parameters, "Parameters must not be null!");
int expected = method.getParameterTypes().length;
int given = parameters.length;
Assert.isTrue(expected == given,
() -> String.format("Incorrect number of parameter values given. Expected %s, got %s!", expected, given));
return linkTo(DummyInvocationUtils.getLastInvocationAware(controller, method, parameters));
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.