Library versions

  • spring-boot-starter-amqp: 2.6.3
  • spring-messaging: 5.3.15
  • kotlin: 1.6.10
  • kotlin-stdlib: 1.6.10
  • kotlint-reflect: 1.6.10

Scenario

Subscribing a particular topic by invoking one of the methods in my controller.

@SubscribeMapping("/sometopic")
fun foo(bar: Bar?) {
  // Method implementation
}

Bug triggered

The nullable Bar in Kotlin cannot be recognized by the HandlerMethod in org.framework.messaging.handler.

Bar is treated as a normal Java object inside the method.

When I invoke the method by passing a nullable object, which would be converted to a Optional<Bar> object in Java at the end, the exception is then thrown.

Comment From: sbrannen

Can you please provide the stack trace showing the IllegalStateException?

Comment From: kimkaesar

Due to the fact that it's inside a citrix session, I couldn't copy the stacktrace and paste it here. I try my best to type it manually, forgive me if I made any typo.

java.lang.IllegalStateException: argument type mismatch
Endpoint [a.b.c.controller]
Method [public x.y.z.Response a.b.c.controller.foo(Bar)] with argument values:
[0] [type=java.util.Optional][value=Optional[Bar [.......]]
  at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:174)
  at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:119)
  at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch(AbstractMethodMessageHandler.java:569)
  at org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler.handleMatch(SimpAnnotationMethodMessageHandler.java:511)
  at org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler.handleMatch(SimpAnnotationMethodMessageHandler.java:94)
  at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessageInternal(AbstractMethodMessageHandler.java:524)
  at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessage(AbstractMethodMessageHandler.java:458)
  at org.springframework.messaging.support.ExecutorSubscribableChannel$SendTask.run(ExecutorSubscribableChannel.java:144)
Caused by: java.lang.illegalArgumentException: argument type mismatch
  at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:169)
  ... 10 more

Comment From: sbrannen

Thanks for providing the stack trace.

We'll look into it.

Comment From: poutsma

Looking at the stack trace, it looks like the method signature itself is fine (i.e. controller.foo(Bar), but the argument somehow got resolved to Optional<Bar> instead of a plain Bar.

I cannot reproduce this issue in a test. If you'd like us to spend more time investigating, please provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.