From 43b831b8d2bd13707fc80febcfca5e052b66bd33 Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Thu, 19 Nov 2020 08:10:17 +0100 Subject: [PATCH] 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 --- .../netty/example/objectecho/ObjectEchoClientHandler.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/example/src/main/java/io/netty/example/objectecho/ObjectEchoClientHandler.java b/example/src/main/java/io/netty/example/objectecho/ObjectEchoClientHandler.java index 96e0a9d73a..c9ad81f6a7 100644 --- a/example/src/main/java/io/netty/example/objectecho/ObjectEchoClientHandler.java +++ b/example/src/main/java/io/netty/example/objectecho/ObjectEchoClientHandler.java @@ -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