jira-importer opened a new issue, #952:
URL: https://github.com/apache/httpcomponents-core/issues/952

   **[Markus 
Thies](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=mthies)** 
opened 
**[HTTPCORE-316](https://issues.apache.org/jira/browse/HTTPCORE-316?redirect=false)**
 and commented
   
   The class org.apache.http.message.HeaderGroup  provides a method clone().
   If clone is called the original object's headers are removed.
   
   The root cause of this is, that the class HeaderGroup has only one attribute 
(headers) which is a List.
   As clone does a shallow copy the List is not cloned (that is correct).
   But within the method clone(), the headers of the newly created clone are 
removed (by calling clear()) but they actually also clear the headers of the 
original object (since it is not a copy).
   
   So this leads to very tricky problems in code where the headers are 
essential to be available in the clone and in the original object.
   
   Original code:
   public Object clone() throws CloneNotSupportedException {
   HeaderGroup clone = (HeaderGroup) super.clone();
   clone.headers.clear();
   clone.headers.addAll(this.headers);
   return clone;
   }
   
   Corrected code:
   public Object clone() throws CloneNotSupportedException {
   HeaderGroup clone = (HeaderGroup) super.clone();
   //BUG: would also clear the headers original
   //clone.headers.clear();
   //clone.headers.addAll(this.headers);
   return clone;
   }
   
   
   
   ---
   
   **Affects:** 4.2.2
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to