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

Can't use lambda expression for MessageHandler #630

Open
sco0ter opened this issue Apr 4, 2018 · 1 comment
Open

Can't use lambda expression for MessageHandler #630

sco0ter opened this issue Apr 4, 2018 · 1 comment

Comments

@sco0ter
Copy link

sco0ter commented Apr 4, 2018

Neither of the following two lambda expression work, when registering a PongMessage handler.

session.addMessageHandler((MessageHandler.Whole<PongMessage>) message -> {
});
session.addMessageHandler(PongMessage.class, message -> {
});

The reason is, that the internal method static Class<?> getHandlerType(MessageHandler handler) returns Object instead of PongMessage for the type.

The workaround for this issue is to not using lambdas, but implement the interface on a class and use that:

class PongHandler implements MessageHandler.Whole<PongMessage>
@dansiviter
Copy link
Contributor

dansiviter commented Jun 28, 2020

I've just come across this one. It looks to be caused by the type erasure of the lambda expression as TyrusSession#notifyPongHandler is trying to infer the type rather than getting it explicitly from the MessageHandlerManager#registeredHandlers. As PongMessage can only use MessageHandler.Whole types, I think this can be replace with getMessageHandler(Class). I'll submit a patch when I get a few minutes.

dansiviter added a commit to dansiviter/tyrus that referenced this issue Jun 29, 2020
dansiviter added a commit to dansiviter/tyrus that referenced this issue Jun 29, 2020
Signed-off-by: Dan Siviter <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants