Let object serialisation exceptions propagate in the Object Echo example (#10807)
Motivation: People may use the object serialisation example as a vehicle to test out sending their own objects across the wire. If those objects are not actually serialisable for some reason, then we need to let the exception propagate so that this becomes obvious to people. Modification: Add a listener to the future that sends the first serialisable message, so that we ensure that any exceptions that shows up during serialisation becomes visible. Without this, the state of the future that sent the first message was never checked or inspected anywhere. Result: Serialisation bugs in code derived from the Object Echo example are much easier to diagnose. This fixes #10777
This commit is contained in:
parent
1c230405fd
commit
3354c7b0bf
@ -15,12 +15,16 @@
|
||||
*/
|
||||
package io.netty.example.objectecho;
|
||||
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static io.netty.channel.ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE;
|
||||
|
||||
/**
|
||||
* Handler implementation for the object echo client. It initiates the
|
||||
* ping-pong traffic between the object echo client and server by sending the
|
||||
@ -43,7 +47,8 @@ public class ObjectEchoClientHandler extends ChannelInboundHandlerAdapter {
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) {
|
||||
// Send the first message if this handler is a client-side handler.
|
||||
ctx.writeAndFlush(firstMessage);
|
||||
ChannelFuture future = ctx.writeAndFlush(firstMessage);
|
||||
future.addListener(FIRE_EXCEPTION_ON_FAILURE); // Let object serialisation exceptions propagate.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user