JDK-4424392 : (cs) CharsetEncoder.encode() misses char after nonmapped one
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2001-03-12
  • Updated: 2001-07-19
  • Resolved: 2001-07-19
Related Reports
Duplicate :  
Description

Name: elR10090			Date: 03/12/2001


The implementation of the method encode() class java.nio.CharsetEncoder
in the jdk1.4.0beta-b55 misses the character if the previous one in
the input character buffer cannot be mapped to an equivalent byte
sequence and the substitution occurs.

The following simple test reveals this problem:

Ctob log:

Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b55)
Java HotSpot(TM) Client VM (build 1.4beta-B55, mixed mode)
Charset: ISO-8859-1
Chars from the source string: \u41 \u7ff \u42 \u43 \uffff \u44 \u45
Bytes after encode: 0x41 0x3f 0x43 0x3f 0x45

Ctob.java source:

import java.nio.*;

public class Ctob {

    final static String charsetName = "ISO-8859-1";
    final static String testString = "A\u07ffBC\uffffDE";

    public static void main(String args[]) throws Exception {
        Charset cs = Charset.forName(charsetName);
        CharsetEncoder encoder = cs.newEncoder();
        System.out.println("Charset: " + cs.name());

        byte[] bytes = new byte[64];
        ByteBuffer bb = ByteBuffer.wrap(bytes);

        System.out.print("Source string chars:" );
        char[] chars = testString.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            System.out.print(" \\u" + Integer.toHexString((int)chars[i]));
        }
        System.out.println("");

        CharBuffer cb = CharBuffer.wrap(testString);
        while (cb.hasRemaining()) {
            encoder.encode(cb, bb, false);
        }
        encoder.flush(bb);
        bb.flip();
        int n = bb.remaining();
        System.out.print("Bytes after encoding:");
        for (int i = 0; i < n; i++) {
            System.out.print(" 0x" + Integer.toHexString((int)bytes[i]));
        }
        System.out.println("");
        bb.clear();
    }
}

This bug affects the following testbase_nsk test:
    nsk/logging/Handler/setEncoding/stencd001
    
I think also that the bug 4424300 has the same reason.
 
======================================================================

Comments
EVALUATION This is a duplicate of bug 4457851. I have included the test case provided here in the evaluation of that bug. iag@eng 2001-07-19
19-07-2001