You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Oleg Kalnichevski (JIRA)" <ji...@apache.org> on 2010/01/12 19:01:55 UTC

[jira] Updated: (HTTPCLIENT-904) HttpMime StringBody constructor throws specification unnecessarily declares UnsupportedEncodingException

     [ https://issues.apache.org/jira/browse/HTTPCLIENT-904?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski updated HTTPCLIENT-904:
-----------------------------------------

         Priority: Trivial  (was: Major)
    Fix Version/s: 4.1 Alpha2
       Issue Type: Improvement  (was: Bug)

I think this is a good idea. I would just throw IllegalArguementException instead of plain RuntimeException

Oleg

> HttpMime StringBody constructor throws specification unnecessarily declares UnsupportedEncodingException
> --------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-904
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-904
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpMime
>    Affects Versions: 4.0.1
>            Reporter: Mark Sinke
>            Priority: Trivial
>             Fix For: 4.1 Alpha2
>
>
> The string body constructors that take a charset unnecessarily throw UnsupportedEncodingException - if you have Charset, the encoding is by definition supported:
>     public StringBody(
>             final String text, 
>             final String mimeType, 
>             Charset charset) throws UnsupportedEncodingException {
>         super(mimeType);
>         if (text == null) {
>             throw new IllegalArgumentException("Text may not be null");
>         }
>         if (charset == null) {
>             charset = Charset.defaultCharset();
>         }
>         this.content = text.getBytes(charset.name());
>         this.charset = charset;
>     }
>     
>     public StringBody(final String text, Charset charset) throws UnsupportedEncodingException {
>         this(text, "text/plain", charset);
>     }
>     
> I suggest to change this to
>     public StringBody(
>             final String text, 
>             final String mimeType, 
>             Charset charset)  {
>         super(mimeType);
>         if (text == null) {
>             throw new IllegalArgumentException("Text may not be null");
>         }
>         if (charset == null) {
>             charset = Charset.defaultCharset();
>         }
>         this.content = text.getBytes(charset);
>         this.charset = charset;
>     }
>     
>     public StringBody(final String text, Charset charset) {
>         this(text, "text/plain", charset);
>     }
> The important change is to change
>         this.content = text.getBytes(charset.name());
> to 
>         this.content = text.getBytes(charset);
> which will not throw and hence the throws specifications can be removed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org