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:
Chris Vest 2020-11-19 08:10:17 +01:00 committed by Norman Maurer
parent 3a58063fe7
commit 43b831b8d2

View File

@ -16,11 +16,14 @@
package io.netty.example.objectecho;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
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 +46,8 @@ public class ObjectEchoClientHandler implements ChannelHandler {
@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