diff --git a/httpclient/src/main/java/org/apache/http/impl/cookie/BasicClientCookie2.java b/httpclient/src/main/java/org/apache/http/impl/cookie/BasicClientCookie2.java index 1fd216e98..8ebc963c8 100644 --- a/httpclient/src/main/java/org/apache/http/impl/cookie/BasicClientCookie2.java +++ b/httpclient/src/main/java/org/apache/http/impl/cookie/BasicClientCookie2.java @@ -93,7 +93,9 @@ public class BasicClientCookie2 extends BasicClientCookie implements SetCookie2, @Override public Object clone() throws CloneNotSupportedException { BasicClientCookie2 clone = (BasicClientCookie2) super.clone(); - clone.ports = this.ports.clone(); + if (this.ports != null) { + clone.ports = this.ports.clone(); + } return clone; } diff --git a/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie2.java b/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie2.java index a6ed4ec5c..275f92302 100644 --- a/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie2.java +++ b/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie2.java @@ -71,6 +71,21 @@ public class TestBasicClientCookie2 { Assert.assertEquals(orig.getPorts()[1], clone.getPorts()[1]); } + @Test + public void testHTTPCLIENT_1031() throws Exception { + BasicClientCookie2 orig = new BasicClientCookie2("name", "value"); + orig.setDomain("domain"); + orig.setPath("/"); + orig.setAttribute("attrib", "stuff"); + BasicClientCookie2 clone = (BasicClientCookie2) orig.clone(); + Assert.assertEquals(orig.getName(), clone.getName()); + Assert.assertEquals(orig.getValue(), clone.getValue()); + Assert.assertEquals(orig.getDomain(), clone.getDomain()); + Assert.assertEquals(orig.getPath(), clone.getPath()); + Assert.assertEquals(orig.getAttribute("attrib"), clone.getAttribute("attrib")); + Assert.assertNull(clone.getPorts()); + } + @Test public void testSerialization() throws Exception { BasicClientCookie2 orig = new BasicClientCookie2("name", "value");