From 9475e262934f3781e7170bf6f3e2c25b2331cbd8 Mon Sep 17 00:00:00 2001 From: Sebastian Bazley Date: Wed, 8 Dec 2010 20:37:53 +0000 Subject: [PATCH] HTTPCLIENT-1031 Cannot clone BasicClientCookie2 without specified ports git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1043664 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/impl/cookie/BasicClientCookie2.java | 4 +++- .../http/impl/cookie/TestBasicClientCookie2.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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");