[#2643] Throw TooLongFrameException instead of using fireExceptionCaught

Motivation:

It's not always the case that there is another handler in the pipeline that will intercept the exceptionCaught event because sometimes users just sub-class. In this case the exception will just hit the end of the pipeline.

Modification:
Throw the TooLongFrameException so that sub-classes can handle it in the exceptionCaught(...) method directly.

Result:
Sub-classes can correctly handle the exception,
This commit is contained in:
Norman Maurer 2014-07-10 06:53:51 +02:00
parent b440fa840b
commit 93b5e832b6

View File

@ -255,7 +255,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder {
int tooLongFrameLength = this.tooLongFrameLength;
this.tooLongFrameLength = 0;
if (!failFast) {
fail(ctx, tooLongFrameLength);
fail(tooLongFrameLength);
}
return null;
}
@ -263,7 +263,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder {
if (minFrameLength > maxFrameLength) {
// Discard read frame.
buffer.skipBytes(minFrameLength + minDelimLength);
fail(ctx, minFrameLength);
fail(minFrameLength);
return null;
}
@ -283,7 +283,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder {
buffer.skipBytes(buffer.readableBytes());
discardingTooLongFrame = true;
if (failFast) {
fail(ctx, tooLongFrameLength);
fail(tooLongFrameLength);
}
}
} else {
@ -295,17 +295,15 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder {
}
}
private void fail(ChannelHandlerContext ctx, long frameLength) {
private void fail(long frameLength) {
if (frameLength > 0) {
ctx.fireExceptionCaught(
new TooLongFrameException(
throw new TooLongFrameException(
"frame length exceeds " + maxFrameLength +
": " + frameLength + " - discarded"));
": " + frameLength + " - discarded");
} else {
ctx.fireExceptionCaught(
new TooLongFrameException(
throw new TooLongFrameException(
"frame length exceeds " + maxFrameLength +
" - discarding"));
" - discarding");
}
}