[FLINK-7402] [runtime] Fix null check in NettyMessage#write This closes #4562
Project: http://git-wip-us.apache.org/repos/asf/flink/repo Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/312e0853 Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/312e0853 Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/312e0853 Branch: refs/heads/master Commit: 312e0853483d1aa5ca182827890c570c44ca6a37 Parents: 31e7bf3 Author: zjureel <zjur...@gmail.com> Authored: Fri Aug 18 14:43:34 2017 +0800 Committer: Greg Hogan <c...@greghogan.com> Committed: Fri Sep 15 16:41:46 2017 -0400 ---------------------------------------------------------------------- .../apache/flink/runtime/io/network/netty/NettyMessage.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flink/blob/312e0853/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyMessage.java ---------------------------------------------------------------------- diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyMessage.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyMessage.java index de50f82..2da144e 100644 --- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyMessage.java +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyMessage.java @@ -38,6 +38,8 @@ import org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise; import org.apache.flink.shaded.netty4.io.netty.handler.codec.LengthFieldBasedFrameDecoder; import org.apache.flink.shaded.netty4.io.netty.handler.codec.MessageToMessageDecoder; +import org.apache.flink.util.Preconditions; + import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -220,6 +222,8 @@ abstract class NettyMessage { @Override ByteBuf write(ByteBufAllocator allocator) throws IOException { + Preconditions.checkNotNull(buffer, "No buffer instance to serialize."); + int length = 16 + 4 + 1 + 4 + buffer.getSize(); ByteBuf result = null; @@ -242,9 +246,7 @@ abstract class NettyMessage { throw new IOException(t); } finally { - if (buffer != null) { - buffer.recycle(); - } + buffer.recycle(); } }