From b76c39318d8edf39759b25990edcc4ef26bb493a Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Tue, 16 Oct 2012 14:23:02 -0700 Subject: [PATCH] Make NoSuchBufferException message more useful --- .../io/netty/handler/codec/CodecUtil.java | 22 +++++++++++++++++++ .../handler/codec/MessageToByteEncoder.java | 2 +- .../codec/MessageToMessageDecoder.java | 2 +- .../codec/MessageToMessageEncoder.java | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/codec/src/main/java/io/netty/handler/codec/CodecUtil.java b/codec/src/main/java/io/netty/handler/codec/CodecUtil.java index 30966c1643..881c3be59a 100644 --- a/codec/src/main/java/io/netty/handler/codec/CodecUtil.java +++ b/codec/src/main/java/io/netty/handler/codec/CodecUtil.java @@ -117,6 +117,28 @@ final class CodecUtil { return false; } + static void addToNextOutboundBuffer(ChannelHandlerContext ctx, Object msg) { + try { + ctx.nextOutboundMessageBuffer().add(msg); + } catch (NoSuchBufferException e) { + NoSuchBufferException newE = + new NoSuchBufferException(e.getMessage() + " (msg: " + msg + ')'); + newE.setStackTrace(e.getStackTrace()); + throw newE; + } + } + + static void addToNextInboundBuffer(ChannelHandlerContext ctx, Object msg) { + try { + ctx.nextInboundMessageBuffer().add(msg); + } catch (NoSuchBufferException e) { + NoSuchBufferException newE = + new NoSuchBufferException(e.getMessage() + " (msg: " + msg + ')'); + newE.setStackTrace(e.getStackTrace()); + throw newE; + } + } + private CodecUtil() { // Unused } diff --git a/codec/src/main/java/io/netty/handler/codec/MessageToByteEncoder.java b/codec/src/main/java/io/netty/handler/codec/MessageToByteEncoder.java index 92b0536485..ed71cc5f5f 100644 --- a/codec/src/main/java/io/netty/handler/codec/MessageToByteEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/MessageToByteEncoder.java @@ -41,7 +41,7 @@ public abstract class MessageToByteEncoder extends ChannelOutboundMessageHand } if (!isEncodable(msg)) { - ctx.nextOutboundMessageBuffer().add(msg); + CodecUtil.addToNextOutboundBuffer(ctx, msg); continue; } diff --git a/codec/src/main/java/io/netty/handler/codec/MessageToMessageDecoder.java b/codec/src/main/java/io/netty/handler/codec/MessageToMessageDecoder.java index 650939d237..401e867ab4 100644 --- a/codec/src/main/java/io/netty/handler/codec/MessageToMessageDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/MessageToMessageDecoder.java @@ -47,7 +47,7 @@ public abstract class MessageToMessageDecoder break; } if (!isDecodable(msg)) { - ctx.nextInboundMessageBuffer().add(msg); + CodecUtil.addToNextInboundBuffer(ctx, msg); notify = true; continue; } diff --git a/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java b/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java index cbc0be41ee..06f8116fa4 100644 --- a/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java @@ -39,7 +39,7 @@ public abstract class MessageToMessageEncoder extends ChannelOutboundMessa } if (!isEncodable(msg)) { - ctx.nextOutboundMessageBuffer().add(msg); + CodecUtil.addToNextOutboundBuffer(ctx, msg); continue; }