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

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

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: Bug
          Components: HttpMime
    Affects Versions: 4.0.1
            Reporter: Mark Sinke


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


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

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-904?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12799176#action_12799176 ] 

Oleg Kalnichevski commented on HTTPCLIENT-904:
----------------------------------------------

Odi, I see your point. Actually HttpMime cannot be considered API stable as its underlying library - mime4j is not yet API stable. We could remove UnsupportedEncodingException if you think this issue is severe enough to warrant API breakage. 

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: Bug
>          Components: HttpMime
>    Affects Versions: 4.0.1
>            Reporter: Mark Sinke
>
> 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


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

Posted by "Mark Sinke (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-904?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12799762#action_12799762 ] 

Mark Sinke commented on HTTPCLIENT-904:
---------------------------------------

I'd be ok with the static factory method. It'll clean up the client code and that is what counts.

> 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


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

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ 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


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

Posted by "Ortwin Glück (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-904?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12799166#action_12799166 ] 

Ortwin Glück commented on HTTPCLIENT-904:
-----------------------------------------

Oleg, the point is that text.getBytes(charset.name()) can never throw the UnsupportedEncodingException. Because it's not possible to obtain Charset instances of unsupported encodings. However due to API compatibility we have to leave the Exception declararion in place unfortunately anyway.

> 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: Bug
>          Components: HttpMime
>    Affects Versions: 4.0.1
>            Reporter: Mark Sinke
>
> 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


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

Posted by "Sam Berlin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-904?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12799249#action_12799249 ] 

Sam Berlin commented on HTTPCLIENT-904:
---------------------------------------

What about a compromise -- a factory method that doesn't throw:

  /** An alternate to new StringBody(CharSet) that doesn't throw an exception. */
  public static StringBody create(CharSet charSet) {
     try {
         return new StringBody(charSet);
     } catch(UnsupportedEncodingException uee) {        
         throw new RuntimeException(uee); // this should never happen
     }
 }

There's precedent in the URI class.  The URI constructor throws, and there's a factory URI.create method that doesn't declare the throwable.

> 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: Bug
>          Components: HttpMime
>    Affects Versions: 4.0.1
>            Reporter: Mark Sinke
>
> 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


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

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-904?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski resolved HTTPCLIENT-904.
------------------------------------------

    Resolution: Won't Fix

Mark,

String#getBytes(Charset) method is available as of Java 1.6 and therefore cannot be used by HttpClient as long as we want to keep it 1.5 compatible.

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: Bug
>          Components: HttpMime
>    Affects Versions: 4.0.1
>            Reporter: Mark Sinke
>
> 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


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

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-904?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12799245#action_12799245 ] 

Oleg Kalnichevski commented on HTTPCLIENT-904:
----------------------------------------------

Folks,

I do not want to take this decision by myself. As far as I am concerned it is not severe enough to warrant API breakage. If no one else votes in favour of making the change , the issue will remain WONTFIX

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: Bug
>          Components: HttpMime
>    Affects Versions: 4.0.1
>            Reporter: Mark Sinke
>
> 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


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

Posted by "Mark Sinke (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-904?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12799172#action_12799172 ] 

Mark Sinke commented on HTTPCLIENT-904:
---------------------------------------

Oleg, Ortwin, 

Removing a throws specification would not break API compatability (not even binary compatability, since the JVM never checks the throws spec anyway; that's up to javac). So another option is to catch the exception and ignore it since it cannot happen anyway.

Like this

try {
    this.content = text.getBytes(charset.name());
} catch (UnsupportedEncodingException e) {
    // cannot happen since charset was known in the first place
}

My calling code now essentially needs to do the code I just wrote, which is a nuisance and will proliferate to all users of the library.



> 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: Bug
>          Components: HttpMime
>    Affects Versions: 4.0.1
>            Reporter: Mark Sinke
>
> 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


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

Posted by "Mark Sinke (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-904?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12799181#action_12799181 ] 

Mark Sinke commented on HTTPCLIENT-904:
---------------------------------------

Sebb,

You rightly point out that consumers *when they recompile* need to change their code - but the thing they need to do is to remove a catch block for an exception that is never thrown. If they go through the mechanics of upgrading the library beyond just a binary replace of the jar file, I'm sure they will be happy to remove the dead code.

Oleg,

I'd be delighted to see the code fixed. The 4.0 HttpClient is so much better than 3.0. Fixing this issue would remove an unnecessary nuisance introduced with 4.0, which we can still fix at this stage.

Thanks,

Mark.

> 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: Bug
>          Components: HttpMime
>    Affects Versions: 4.0.1
>            Reporter: Mark Sinke
>
> 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


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

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-904?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12799178#action_12799178 ] 

Sebb commented on HTTPCLIENT-904:
---------------------------------

Removing a checked exception does affect consumers of the library.

If the caller currently catches UCE, they would have to amend their code if the method no longer throws UCE.

I just tried a test with the following code:

public class Test{
    private static void xys() //throws java.io.UnsupportedEncodingException 
    {        
    }
    private static void call(){
        try {
            xys();
        } catch (java.io.UnsupportedEncodingException e) {
            e.printStackTrace();
        }        
    }
}

and I get:

Test.java:8: exception java.io.UnsupportedEncodingException is never thrown in body of corresponding try statement
        } catch (java.io.UnsupportedEncodingException e) {

It may not affect the code at run-time, but the user will have to amend their code before recompiling it.

> 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: Bug
>          Components: HttpMime
>    Affects Versions: 4.0.1
>            Reporter: Mark Sinke
>
> 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


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

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-904?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski resolved HTTPCLIENT-904.
------------------------------------------

    Resolution: Fixed

Fixed in SVN trunk.

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


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

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-904?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski reopened HTTPCLIENT-904:
------------------------------------------


> 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