Return-Path: Delivered-To: apmail-hc-dev-archive@www.apache.org Received: (qmail 36413 invoked from network); 12 Jan 2010 18:02:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 12 Jan 2010 18:02:17 -0000 Received: (qmail 83138 invoked by uid 500); 12 Jan 2010 18:02:17 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 83064 invoked by uid 500); 12 Jan 2010 18:02:17 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 83054 invoked by uid 99); 12 Jan 2010 18:02:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Jan 2010 18:02:16 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Jan 2010 18:02:16 +0000 Received: from brutus.apache.org (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id BE5BB234C1F2 for ; Tue, 12 Jan 2010 10:01:55 -0800 (PST) Message-ID: <448948439.186081263319315778.JavaMail.jira@brutus.apache.org> Date: Tue, 12 Jan 2010 18:01:55 +0000 (UTC) From: "Oleg Kalnichevski (JIRA)" To: dev@hc.apache.org Subject: [jira] Reopened: (HTTPCLIENT-904) HttpMime StringBody constructor throws specification unnecessarily declares UnsupportedEncodingException In-Reply-To: <64330854.179051263291534500.JavaMail.jira@brutus.apache.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ 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