Skip to content

InvocableHandlerMethod incorrectly resolves arguments by type #25033

@garyrussell

Description

@garyrussell

getMethodArgumentValues() performs early argument resolution by type; even when parameters are annotated and should be resolved by the resolvers.

@Test
void testInvocableHandlerMethod() throws Exception {
	TestClass bean = new TestClass();
	InvocableHandlerMethod handler = messageHandlerFactory().createInvocableHandlerMethod(bean,
			TestClass.class.getDeclaredMethod("defMethod", Object.class, String.class));
	handler.invoke(new GenericMessage<>("foo", Collections.singletonMap("bar", "baz")), "foo");
	assertThat(bean.object).isEqualTo("foo");
	assertThat(bean.bar).isEqualTo("baz");
}

private MessageHandlerMethodFactory messageHandlerFactory() {
	DefaultMessageHandlerMethodFactory defaultFactory = new DefaultMessageHandlerMethodFactory();
	DefaultFormattingConversionService cs = new DefaultFormattingConversionService();
	defaultFactory.setConversionService(cs);
	GenericMessageConverter messageConverter = new GenericMessageConverter(cs);
	defaultFactory.setMessageConverter(messageConverter);
	defaultFactory.afterPropertiesSet();
	return defaultFactory;
}

public static class TestClass {

	Object object;

	String bar;

	public void defMethod(Object obj, @Header("bar") String bar) {
		this.object = obj;
		this.bar = bar;
	}

}

Both parameters are resolved via the providedArgs (foo, foo).

Manifested in this Spring for Apache Kafka issue.

I can probably work around it in spring-kafka by subclassing and overriding findProvidedArgument() to ignore parameters with @Header annotations, but thought I should raise it here because the same issue would apply to other messaging apps.

Oops - findProvidedArgument is static, and I can't override getMethodArgumentValues because it uses private fields.

Metadata

Metadata

Assignees

Labels

in: messagingIssues in messaging modules (jms, messaging)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions