Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MvcUriComponentsBuilder does not support bridged methods [SPR-12977] #17568

Closed
spring-issuemaster opened this issue May 4, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented May 4, 2015

Sam Brannen opened SPR-12977 and commented

Status Quo

Given the example classes listed below, an invocation of fromMethodName(PersonCrudController.class, "get", new Long(42)).build() on MvcUriComponentsBuilder fails with the following exception.

java.lang.IllegalArgumentException: Found two methods named 'get' accepting arguments [42] on controller org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilderTests$PersonCrudController: [public org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilderTests$Person org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilderTests$PersonCrudController.get(java.lang.Long)] and [public java.lang.Object org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilderTests$PersonCrudController.get(java.lang.Object)]

Analysis

MvcUriComponentsBuilder.getMethod(Class<?>, String, Object...) throws an IllegalArgumentException if it encounters both a bridge and bridged method which naturally have the same name and signature (excluding argument types and return type). In the failing scenario described in this issue, Person get(Long) is the bridged method, and Object get(Object) is the bridge method.

Example Classes

public abstract class AbstractCrudController<T, ID> {
	public abstract T get(ID id);
}

public class PersonCrudController extends AbstractCrudController<Person, Long> {

	@RequestMapping(path = "/{id}", method = RequestMethod.GET)
	public Person get(@PathVariable Long id) {
		return new Person();
	}
}

Affects: 4.0 GA

Referenced from: commits 205e5df, e9c4db3, 859751b

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented May 4, 2015

Sam Brannen commented

Introduced failing (but currently disabled) test in MvcUriComponentsBuilderTests in GitHub commit 859751b.

Search for TODO.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented May 5, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.