diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpHeaders.java b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpHeaders.java index 0711fb3916..2b70656508 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpHeaders.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpHeaders.java @@ -29,6 +29,8 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.Set; +import static io.netty.util.internal.ObjectUtil.checkNotNull; + public class DefaultHttpHeaders extends HttpHeaders { private static final int BUCKET_SIZE = 17; @@ -382,9 +384,7 @@ public class DefaultHttpHeaders extends HttpHeaders { } private static CharSequence toCharSequence(Object value) { - if (value == null) { - return null; - } + checkNotNull(value, "value"); if (value instanceof CharSequence) { return (CharSequence) value; } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeadersTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeadersTest.java index 5d98726905..47302c7425 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeadersTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeadersTest.java @@ -55,4 +55,16 @@ public class HttpHeadersTest { assertThat(HttpHeaders.equalsIgnoreCase("bar", null), is(false)); assertThat(HttpHeaders.equalsIgnoreCase("FoO", "fOo"), is(true)); } + + @Test(expected = NullPointerException.class) + public void testSetNullHeaderValueValidate() { + HttpHeaders headers = new DefaultHttpHeaders(true); + headers.set("test", (CharSequence) null); + } + + @Test(expected = NullPointerException.class) + public void testSetNullHeaderValueNotValidate() { + HttpHeaders headers = new DefaultHttpHeaders(false); + headers.set("test", (CharSequence) null); + } }