mardi 29 septembre 2020

Why do I get a WrongMethodTypeException on invokeExact even though MethodHandle is OK

I am trying to call an invoke method and there is an error that I cannot explain. I have heard that the Invoke Exact method has to return but it did not work even then.

public void exec(String id, ChannelHandlerContext ctx, ByteBuf byteBuf) {
    assert ctx != null;
    assert byteBuf != null;
    try {
        MethodHandle methodHandle = this.methods.get(id);

        Boolean b = (Boolean) methodHandle.invokeExact(ctx, byteBuf);

        //            this.methods.get(id).invoke(massageExchanger, ctx, byteBuf);

        //            this.methods.get(id).invokeWithArguments(ctx, byteBuf);
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }
}

on this code the Programm crash

Boolean b = (Boolean) methodHandle.invokeExact(ctx, byteBuf);

java.lang.invoke.WrongMethodTypeException: expected (,ChannelHandlerContext,ByteBuf)Boolean but found (ChannelHandlerContext,ByteBuf)Boolean
    at java.base/java.lang.invoke.Invokers.newWrongMethodTypeException(Invokers.java:476)
    at java.base/java.lang.invoke.Invokers.checkExactType(Invokers.java:485)
    at de.moldiy.spaceexplorer.MessageExchangerManager.exec(MessageExchangerManager.java:51)
    at de.moldiy.spaceexplorer.MessageHandler.channelRead0(MessageHandler.java:19)
    at de.moldiy.spaceexplorer.MessageHandler.channelRead0(MessageHandler.java:8)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:835)

This is the class that contains the method I want to call

s.loadMessageExchanger(new ServerMessageExchanger() {
    @TrafficID(id = "cords")
    public Boolean setCords(ChannelHandlerContext ctx,ByteBuf byteBuf) {
       System.out.println("jaaa");
       return true;
    }
});




Aucun commentaire:

Enregistrer un commentaire