http core 4.2.2 StringEntity 的一个疑问
代码在org.apache.http.entity.StringEntity中。版本4.2.2。
感觉代码和注释不匹配。
同时,没有处理好contentType为null的情况。
4.2.3中无该问题。已经修复。
/** * Creates a StringEntity with the specified content and content type. * * @param string content to be used. Not {@code null}. * @param contentType content type to be used. May be {@code null}, in which case the default * MIME type {@link ContentType#TEXT_PLAIN} is assumed. * * @throws IllegalArgumentException if the string parameter is null * * @since 4.2 */ public StringEntity(final String string, final ContentType contentType) { super(); if (string == null) { throw new IllegalArgumentException("Source string may not be null"); } Charset charset = contentType != null ? contentType.getCharset() : null; try { this.content = string.getBytes(charset.name()); } catch (UnsupportedEncodingException ex) { // should never happen throw new UnsupportedCharsetException(charset.name()); } if (contentType != null) { setContentType(contentType.toString()); } }