harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Ellison (JIRA)" <j...@apache.org>
Subject [jira] Assigned: (HARMONY-99) java.nio.charset.CharsetDecoder.decode(ByteBuffer in) does not throw MalformedInputException when buffer's current position is not legal
Date Fri, 17 Feb 2006 11:53:25 GMT
     [ http://issues.apache.org/jira/browse/HARMONY-99?page=all ]

Tim Ellison reassigned HARMONY-99:
----------------------------------

    Assign To: Tim Ellison

> java.nio.charset.CharsetDecoder.decode(ByteBuffer in) does not throw MalformedInputException
when buffer's current position is not legal
> ----------------------------------------------------------------------------------------------------------------------------------------
>
>          Key: HARMONY-99
>          URL: http://issues.apache.org/jira/browse/HARMONY-99
>      Project: Harmony
>         Type: Bug
>   Components: Classlib
>     Reporter: Svetlana Samoilenko
>     Assignee: Tim Ellison
>  Attachments: CharsetDecoder_patch.txt
>
> According to 1.4.2 and 1.5 java.nio.charset.CharsetDecoder.decode(ByteBuffer in) throws
> MalformedInputException - If the byte sequence starting at the input buffer's current
position is not legal for this charset and the current malformed-input action is CodingErrorAction.REPORT.
> Harmony does not throw MalformedInputException in this case as test listed below shows.

> Code to reproduce: 
> import java.nio.*;
> import java.nio.charset.*;
> public class test2 { 
>     public static void main(String[] args) throws Exception {
>         Charset cs =Charset.forName("utf-16");
>         CharsetDecoder decoder = cs.newDecoder();
>         decoder.onMalformedInput(CodingErrorAction.REPORT);
>         decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
>      
>         CharBuffer out = CharBuffer.allocate(10);
>         ByteBuffer in = ByteBuffer.wrap(new byte[] {  109, 97, 109});
>         CharBuffer res1 = decoder.decode(in);
>         //output
>         System.out.println("CharBuffer=="+res1);
>         System.out.println("CharBuffer.position =="+res1.position());
>         System.out.println("toHexString=="+Integer.toHexString(res1.charAt(0)));
>         System.out.println("ByteBuffer.position()=="+in.position());
>         System.out.println("ByteBuffer.remaining()=="+in.remaining());
>     }
> } 
> Steps to Reproduce: 
> 1. Build Harmony (check-out on 2006-01-30) j2se subset as described in README.txt. 
> 2. Compile test2.java using BEA 1.4 javac 
> > javac -d . test2.java 
> 3. Run java using compatible VM (J9) 
> > java -showversion test2
> Output: 
> C:\tmp>C:\jrockit-j2sdk1.4.2_04\bin\java.exe -showversion test2 
> java version "1.4.2_04" 
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) 
> BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32, Native
Threads, GC strategy: parallel) 
> java.nio.charset.MalformedInputException: Input length = 1
>         at java.nio.charset.CoderResult.throwException()V(CoderResult.java:260)
>         at java.nio.charset.CharsetDecoder.decode(Ljava.nio.ByteBuffer;)Ljava.nio.CharBuffer;(CharsetDecoder.java:763)
>         at test2.main([Ljava.lang.String;)V(test2.java:34)
> C:\tmp>C:\harmony\trunk\deploy\jre\bin\java -showversion test2 
> (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable.

> res1==
> res1==0
> toHexString==6d61
> ByteBuffer.position()==3
> ByteBuffer.remaining()==0
> Suggested junit test case:
> ------------------------ CharsetDecoderTest.java -------------------------------------------------

> import junit.framework.*; 
> import java.nio.*;
> import java.nio.charset.*;
> public class CharsetDecoderTest extends TestCase { 
>     public static void main(String[] args) { 
>         junit.textui.TestRunner.run(CharsetDecoderTest.class); 
>     } 
>     public void test_decode() { 
>             try {
>                 Charset cs =Charset.forName("utf-16");
>                 CharsetDecoder decoder = cs.newDecoder();
>                 decoder.onMalformedInput(CodingErrorAction.REPORT);
>                 decoder.onUnmappableCharacter(CodingErrorAction.REPORT); 
>                 CharBuffer out = CharBuffer.allocate(10);
>                 ByteBuffer in = ByteBuffer.wrap(new byte[] {  109, 97, 109});
>                 CharBuffer res1 = decoder.decode(in);
>                 fail("MalformedInputException should have thrown");
>            } catch (MalformedInputException e) {
>                //expected
>            } catch (CharacterCodingException e) {
>                fail("unexpected CharacterCodingException");
>            }
>     } 
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message