HTTPCLIENT-1494: null check in StringBody constructor

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1585944 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2014-04-09 11:42:56 +00:00
parent 7b9408e75f
commit cb983ea5b0
2 changed files with 11 additions and 0 deletions

View File

@ -152,6 +152,7 @@ public class StringBody extends AbstractContentBody {
*/
public StringBody(final String text, final ContentType contentType) {
super(contentType);
Args.notNull(text, "Text");
final Charset charset = contentType.getCharset();
this.content = text.getBytes(charset != null ? charset : Consts.ASCII);
}

View File

@ -65,6 +65,16 @@ public class TestMultipartContentBody {
Assert.assertEquals(MIME.ENC_8BIT, b2.getTransferEncoding());
}
@Test(expected=IllegalArgumentException.class)
public void testStringBodyInvalidConstruction1() throws Exception {
new StringBody(null, ContentType.DEFAULT_TEXT);
}
@Test(expected=IllegalArgumentException.class)
public void testStringBodyInvalidConstruction2() throws Exception {
new StringBody("stuff", (ContentType) null);
}
@Test
public void testInputStreamBody() throws Exception {
final byte[] stuff = "Stuff".getBytes(Consts.ASCII);