HTTPCLIENT-1399: fixed NPE in RequestBuilder

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1523642 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2013-09-16 13:29:25 +00:00
parent eff62c7a6e
commit 11536d3d07
3 changed files with 16 additions and 2 deletions

View File

@ -1,3 +1,12 @@
Changes since 4.3
-------------------
* [HTTPCLIENT-1399] Fixed NPE in RequestBuilder.
Contributed by Oleg Kalnichevski <olegk at apache.org>
Release 4.3 Final
-------------------

View File

@ -226,7 +226,7 @@ public class RequestBuilder {
}
public RequestBuilder setHeader(final Header header) {
if (headergroup != null) {
if (headergroup == null) {
headergroup = new HeaderGroup();
}
this.headergroup.updateHeader(header);
@ -234,7 +234,7 @@ public class RequestBuilder {
}
public RequestBuilder setHeader(final String name, final String value) {
if (headergroup != null) {
if (headergroup == null) {
headergroup = new HeaderGroup();
}
this.headergroup.updateHeader(new BasicHeader(name, value));

View File

@ -195,6 +195,11 @@ public class TestRequestBuilder {
Assert.assertEquals(0, builder.getHeaders("header1").length);
Assert.assertSame(null, builder.getEntity());
Assert.assertSame(null, builder.getConfig());
builder.setHeader(h2)
.setHeader("header1", "a-lot-more-stuff");
Assert.assertSame("a-lot-more-stuff", builder.getLastHeader("header1").getValue());
Assert.assertEquals(1, builder.getHeaders("header1").length);
}
@Test(expected=IllegalArgumentException.class)