diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/DefaultHttp2Headers.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/DefaultHttp2Headers.java index 7fda494f08..a4085d8dfd 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/DefaultHttp2Headers.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/DefaultHttp2Headers.java @@ -35,8 +35,8 @@ public final class DefaultHttp2Headers extends Http2Headers { private final HeaderEntry head; private DefaultHttp2Headers(Builder builder) { - this.entries = builder.entries; - this.head = builder.head; + entries = builder.entries; + head = builder.head; } @Override @@ -126,7 +126,7 @@ public final class DefaultHttp2Headers extends Http2Headers { } /** - * Builds instances of {@link DefaultHttp2Header}. + * Builds instances of {@link DefaultHttp2Headers}. */ public static class Builder { private HeaderEntry[] entries; @@ -344,6 +344,52 @@ public final class DefaultHttp2Headers extends Http2Headers { } return value.toString(); } + + /** + * Validate a HTTP2 header value. Does not validate max length. + */ + private static void validateHeaderValue(String value) { + if (value == null) { + throw new NullPointerException("value"); + } + for (int i = 0; i < value.length(); i ++) { + char c = value.charAt(i); + if (c == 0) { + throw new IllegalArgumentException( + "value contains null character: " + value); + } + } + } + + /** + * Validate a HTTP2 header name. + */ + private static void validateHeaderName(String name) { + if (name == null) { + throw new NullPointerException("name"); + } + if (name.isEmpty()) { + throw new IllegalArgumentException( + "name cannot be length zero"); + } + // Since name may only contain ascii characters, for valid names + // name.length() returns the number of bytes when UTF-8 encoded. + if (name.length() > MAX_VALUE_LENGTH) { + throw new IllegalArgumentException( + "name exceeds allowable length: " + name); + } + for (int i = 0; i < name.length(); i ++) { + char c = name.charAt(i); + if (c == 0) { + throw new IllegalArgumentException( + "name contains null character: " + name); + } + if (c > 127) { + throw new IllegalArgumentException( + "name contains non-ascii character: " + name); + } + } + } } private static int hash(String name) { @@ -393,52 +439,6 @@ public final class DefaultHttp2Headers extends Http2Headers { return hash % BUCKET_SIZE; } - /** - * Validate a HTTP2 header name. - */ - private static void validateHeaderName(String name) { - if (name == null) { - throw new NullPointerException("name"); - } - if (name.isEmpty()) { - throw new IllegalArgumentException( - "name cannot be length zero"); - } - // Since name may only contain ascii characters, for valid names - // name.length() returns the number of bytes when UTF-8 encoded. - if (name.length() > MAX_VALUE_LENGTH) { - throw new IllegalArgumentException( - "name exceeds allowable length: " + name); - } - for (int i = 0; i < name.length(); i ++) { - char c = name.charAt(i); - if (c == 0) { - throw new IllegalArgumentException( - "name contains null character: " + name); - } - if (c > 127) { - throw new IllegalArgumentException( - "name contains non-ascii character: " + name); - } - } - } - - /** - * Validate a HTTP2 header value. Does not validate max length. - */ - private static void validateHeaderValue(String value) { - if (value == null) { - throw new NullPointerException("value"); - } - for (int i = 0; i < value.length(); i ++) { - char c = value.charAt(i); - if (c == 0) { - throw new IllegalArgumentException( - "value contains null character: " + value); - } - } - } - private final class HeaderIterator implements Iterator> { private HeaderEntry current = head; diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/Http2Headers.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/Http2Headers.java index 478c13a7da..799cb97607 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/Http2Headers.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/Http2Headers.java @@ -98,12 +98,12 @@ public abstract class Http2Headers implements Iterable> { private final String value; - private HttpName(String value) { + HttpName(String value) { this.value = value; } public String value() { - return this.value; + return value; } } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/DefaultInboundFlowController.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/DefaultInboundFlowController.java index ca29588dcf..e8eca46d58 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/DefaultInboundFlowController.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/DefaultInboundFlowController.java @@ -37,6 +37,9 @@ public class DefaultInboundFlowController implements InboundFlowController { private final Map streamWindows = new HashMap(); public DefaultInboundFlowController(Http2Connection connection) { + if (connection == null) { + throw new NullPointerException("connecton"); + } connection.addListener(new Http2Connection.Listener() { @Override public void streamCreated(int streamId) { diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/DefaultOutboundFlowController.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/DefaultOutboundFlowController.java index 031dc27bc7..3a9747e556 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/DefaultOutboundFlowController.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/DefaultOutboundFlowController.java @@ -42,6 +42,9 @@ public class DefaultOutboundFlowController implements OutboundFlowController { private int connectionWindowSize = DEFAULT_FLOW_CONTROL_WINDOW_SIZE; public DefaultOutboundFlowController(Http2Connection connection) { + if (connection == null) { + throw new NullPointerException("connection"); + } this.connection = connection; connection.addListener(new Http2Connection.Listener() { @Override diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/Http2ConnectionHandler.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/Http2ConnectionHandler.java index 1d310593bb..6bf6d8a35f 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/Http2ConnectionHandler.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/Http2ConnectionHandler.java @@ -65,6 +65,15 @@ public class Http2ConnectionHandler extends ChannelHandlerAdapter { public Http2ConnectionHandler(final Http2Connection connection, final InboundFlowController inboundFlow, final OutboundFlowController outboundFlow) { + if (connection == null) { + throw new NullPointerException("connection"); + } + if (inboundFlow == null) { + throw new NullPointerException("inboundFlow"); + } + if (outboundFlow == null) { + throw new NullPointerException("outboundFlow"); + } this.connection = connection; this.inboundFlow = inboundFlow; this.outboundFlow = outboundFlow; diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/Http2ConnectionUtil.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/Http2ConnectionUtil.java index da1b4de9bf..d92f1b8468 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/Http2ConnectionUtil.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/connection/Http2ConnectionUtil.java @@ -22,6 +22,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http2.draft10.Http2Exception; +import io.netty.util.CharsetUtil; /** * Constants and utility method used for encoding/decoding HTTP2 frames. @@ -51,7 +52,7 @@ public final class Http2ConnectionUtil { ByteBuf debugData = Unpooled.EMPTY_BUFFER; if (cause != null) { // Create the debug message. - byte[] msg = cause.getMessage().getBytes(); + byte[] msg = cause.getMessage().getBytes(CharsetUtil.UTF_8); debugData = ctx.alloc().buffer(msg.length); debugData.writeBytes(msg); } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/AbstractHttp2FrameUnmarshaller.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/AbstractHttp2FrameUnmarshaller.java index 99f1059601..187bdd2b1b 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/AbstractHttp2FrameUnmarshaller.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/AbstractHttp2FrameUnmarshaller.java @@ -30,7 +30,7 @@ public abstract class AbstractHttp2FrameUnmarshaller implements Http2FrameUnmars @Override public final Http2FrameUnmarshaller unmarshall(Http2FrameHeader header) throws Http2Exception { if (header == null) { - throw new IllegalArgumentException("header must be non-null."); + throw new NullPointerException("header"); } validate(header); diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/Http2FrameDecoder.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/Http2FrameDecoder.java index 87f1d35302..7e6bad0dbb 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/Http2FrameDecoder.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/Http2FrameDecoder.java @@ -54,6 +54,9 @@ public class Http2FrameDecoder extends ByteToMessageDecoder { } public Http2FrameDecoder(Http2FrameUnmarshaller frameUnmarshaller) { + if (frameUnmarshaller == null) { + throw new NullPointerException("frameUnmarshaller"); + } this.frameUnmarshaller = frameUnmarshaller; state = State.FRAME_HEADER; } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/Http2HeadersFrameUnmarshaller.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/Http2HeadersFrameUnmarshaller.java index 5beff990a6..ec7653a5af 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/Http2HeadersFrameUnmarshaller.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/Http2HeadersFrameUnmarshaller.java @@ -40,7 +40,7 @@ public class Http2HeadersFrameUnmarshaller extends AbstractHeadersUnmarshaller { public Http2HeadersFrameUnmarshaller(Http2HeadersDecoder headersDecoder) { if (headersDecoder == null) { - throw new IllegalArgumentException("headersDecoder must not be null."); + throw new NullPointerException("headersDecoder"); } this.headersDecoder = headersDecoder; } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/Http2PushPromiseFrameUnmarshaller.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/Http2PushPromiseFrameUnmarshaller.java index 4080603f43..b2d73c04ff 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/Http2PushPromiseFrameUnmarshaller.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/decoder/Http2PushPromiseFrameUnmarshaller.java @@ -39,7 +39,7 @@ public class Http2PushPromiseFrameUnmarshaller extends AbstractHeadersUnmarshall public Http2PushPromiseFrameUnmarshaller(Http2HeadersDecoder headersDecoder) { if (headersDecoder == null) { - throw new IllegalArgumentException("headersDecoder must not be null."); + throw new NullPointerException("headersDecoder"); } this.headersDecoder = headersDecoder; } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/encoder/AbstractHttp2FrameMarshaller.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/encoder/AbstractHttp2FrameMarshaller.java index 6db8d6f370..e23c52720c 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/encoder/AbstractHttp2FrameMarshaller.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/encoder/AbstractHttp2FrameMarshaller.java @@ -32,7 +32,7 @@ public abstract class AbstractHttp2FrameMarshaller impleme protected AbstractHttp2FrameMarshaller(Class frameType) { if (frameType == null) { - throw new IllegalArgumentException("frameType must be non-null."); + throw new NullPointerException("frameType"); } this.frameType = frameType; } @@ -41,7 +41,7 @@ public abstract class AbstractHttp2FrameMarshaller impleme public final void marshall(Http2Frame frame, ByteBuf out, ByteBufAllocator alloc) throws Http2Exception { if (frame == null) { - throw new IllegalArgumentException("frame must be non-null."); + throw new NullPointerException("frame"); } if (!frameType.isAssignableFrom(frame.getClass())) { diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/encoder/Http2FrameEncoder.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/encoder/Http2FrameEncoder.java index 5514ed0d97..0388c071df 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/encoder/Http2FrameEncoder.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/encoder/Http2FrameEncoder.java @@ -36,6 +36,9 @@ public class Http2FrameEncoder extends MessageToByteEncoder { } public Http2FrameEncoder(Http2FrameMarshaller frameMarshaller) { + if (frameMarshaller == null) { + throw new NullPointerException("frameMarshaller"); + } this.frameMarshaller = frameMarshaller; } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/encoder/Http2HeadersFrameMarshaller.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/encoder/Http2HeadersFrameMarshaller.java index 7fb90973d2..1ba8bda252 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/encoder/Http2HeadersFrameMarshaller.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/draft10/frame/encoder/Http2HeadersFrameMarshaller.java @@ -36,7 +36,7 @@ public class Http2HeadersFrameMarshaller extends AbstractHttp2FrameMarshaller