Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 90746 invoked from network); 8 Feb 2007 17:53:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Feb 2007 17:53:30 -0000 Received: (qmail 33606 invoked by uid 500); 8 Feb 2007 17:53:35 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 33567 invoked by uid 500); 8 Feb 2007 17:53:35 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 33322 invoked by uid 99); 8 Feb 2007 17:53:35 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Feb 2007 09:53:34 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Feb 2007 09:53:26 -0800 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 67C2442968B for ; Thu, 8 Feb 2007 09:53:06 -0800 (PST) Message-ID: <16008796.1170957186422.JavaMail.jira@brutus> Date: Thu, 8 Feb 2007 09:53:06 -0800 (PST) From: "Alexei Zakharov (JIRA)" To: commits@harmony.apache.org Subject: [jira] Commented: (HARMONY-2467) [classlib][nio charset] java.nio.charset.CharsetDecoder(cs, Float.MIN_VALUE,Float.MIN_VALUE) does not throw IllegalArgumentException In-Reply-To: <25232761.1165328182641.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/HARMONY-2467?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12471422 ] Alexei Zakharov commented on HARMONY-2467: ------------------------------------------ I can't say I completely understand the RI's logic here. Why maxCharPerByte shouldn't be less than 1? If we take pure 16-bit unicode representation then maximum number of characters per byte should be 0.5, because it requires minimum two bytes to store any UTF-16 character (see [1] for example). Right? However, if you run the following test on RI --- import java.nio.charset.*; public class CharsetTest { public static void main(String argv[]) { String cnames[] = {"UTF-16", "UTF-8", "ISO-8859-1", "US-ASCII", "UTF-16BE"}; for (String cname : cnames) { Charset cs = Charset.forName(cname); System.out.println(cname + ": " + cs.newDecoder().maxCharsPerByte()); } } } --- You'll see: UTF-16: 1.0 UTF-8: 2.0 ISO-8859-1: 1.0 US-ASCII: 1.0 UTF-16BE: 1.0 I miss something very important probably. How can we produce two chars with just one byte of input with UTF-8? Any comments? [1] http://www.unicode.org/faq/utf_bom.html#37 > [classlib][nio charset] java.nio.charset.CharsetDecoder(cs, Float.MIN_VALUE,Float.MIN_VALUE) does not throw IllegalArgumentException > ------------------------------------------------------------------------------------------------------------------------------------ > > Key: HARMONY-2467 > URL: https://issues.apache.org/jira/browse/HARMONY-2467 > Project: Harmony > Issue Type: Bug > Components: Classlib > Reporter: Anton Ivanov > Assigned To: Alexei Zakharov > Priority: Minor > Attachments: H-2467.patch > > > According to the specification constructor must throw IllegalArgumentException if the preconditions on the parameters do not hold. > java.nio.charset.CharsetDecoder(cs, Float.MIN_VALUE,Float.MIN_VALUE) does not throw IllegalArgumentException while RI does with message: > java.lang.IllegalArgumentException: Replacement too long > Test to reproduce the problem: > import junit.framework.TestCase; > import java.nio.charset.*; > import java.nio.*; > public class test10036 extends TestCase { > public void test1 () { > try { > CharsetDecoderImpl obj = new CharsetDecoderImpl(Charset.forName("UTF-8"), > Float.MIN_VALUE , Float.MIN_VALUE ); > fail("IllegalArgumentException should be thrown"); > } catch (IllegalArgumentException e) { > //expected > } > } > } > class CharsetDecoderImpl extends CharsetDecoder{ > public CharsetDecoderImpl(Charset cs, float averageBytesPerChar, > float maxBytesPerChar){ > super(cs, averageBytesPerChar, maxBytesPerChar); > } > public CoderResult decodeLoop(ByteBuffer out, CharBuffer in) { > return CoderResult.UNDERFLOW; > } > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.