Skip to content

Breaking change in semantics of WebMvcLinkBuilder.linkTo(Class<?>, Method, Object…) in 1.3.4 #1720

Open
@EarthCitizen

Description

@EarthCitizen

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));
	}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions