harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexei Zakharov (JIRA)" <j...@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
Date Thu, 08 Feb 2007 17:53:06 GMT

    [ 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.


Mime
View raw message