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 ab3dce49d1..2f44f6dd5b 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 @@ -79,9 +79,11 @@ public class HttpHeadersTest { headers.add(headers); } - @Test(expected = IllegalArgumentException.class) - public void testSetSelf() { + @Test + public void testSetSelfIsNoOp() { HttpHeaders headers = new DefaultHttpHeaders(false); + headers.add("name", "value"); headers.set(headers); + assertEquals(1, headers.size()); } } diff --git a/codec/src/main/java/io/netty/handler/codec/DefaultHeaders.java b/codec/src/main/java/io/netty/handler/codec/DefaultHeaders.java index 89fe19561e..cc9b6a2db3 100644 --- a/codec/src/main/java/io/netty/handler/codec/DefaultHeaders.java +++ b/codec/src/main/java/io/netty/handler/codec/DefaultHeaders.java @@ -543,7 +543,7 @@ public class DefaultHeaders> implements Headers public T set(Headers headers) { checkNotNull(headers, "headers"); if (headers == this) { - throw new IllegalArgumentException("can't add to itself."); + return thisT(); } clear(); if (headers instanceof DefaultHeaders) { diff --git a/codec/src/test/java/io/netty/handler/codec/DefaultHeadersTest.java b/codec/src/test/java/io/netty/handler/codec/DefaultHeadersTest.java index 5f8472c385..ceee0b80be 100644 --- a/codec/src/test/java/io/netty/handler/codec/DefaultHeadersTest.java +++ b/codec/src/test/java/io/netty/handler/codec/DefaultHeadersTest.java @@ -390,9 +390,11 @@ public class DefaultHeadersTest { headers.add(headers); } - @Test(expected = IllegalArgumentException.class) - public void testSetSelf() { + @Test + public void testSetSelfIsNoOp() { TestDefaultHeaders headers = newInstance(); + headers.add("name", "value"); headers.set(headers); + assertEquals(1, headers.size()); } }