Name: ooR10006 Date: 03/11/2001
jdk1.4.0beta-b54 API implementation, class java.lang.String, method getBytes("ASCII")
returns wrong array of bytes for the string which contains non-mappable according to
ASCII charset characters,
for the string "str\u00EA\u00FF\u00DD\u00BF\u00C1\u00A0" it returns array of
length 6:
(byte)115 (byte)116 (byte)114 (byte)63 (byte)63 (byte)63
jdk1.3.0fcsC returns array of length 9 with all non-mappable chars substituted
with '?' (int decimal value 63).
(byte)115 (byte)116 (byte)114 (byte)63 (byte)63 (byte)63 (byte)63 (byte)63 (byte)63
The following example shows this:
import java.io.UnsupportedEncodingException;
public class Test {
public static void main(String[] args){
String str = "";
try {
byte[] bytes = "str\u00EA\u00FF\u00DD\u00BF\u00C1\u00A0".getBytes("ASCII");
for (int i = 0; i < bytes.length; ++i){
str += Byte.toString(bytes[i]) + " ";
}
System.out.println(bytes.length);
System.out.println(str);
} catch (UnsupportedEncodingException ue){
System.out.println(ue);
}
}
}
novo1% jdk1.3.0fcsC/solaris/bin/java Test
9
115 116 114 63 63 63 63 63 63
novo1% jdk1.4.0beta-b54/solsparc/bin/java Test
6
115 116 114 63 63 63
novo1%
Due to this Merlin JCK test api/java_lang/String/i18n.html#i18nCtorEncodings[String2211]
fails on the platforms with "ASCII" default charset.
======================================================================
- duplicates
-
JDK-4457851 (cs) JCK13a api/java_io/CharacterEncoding/primarySBCS.html#ISO_8859_1 Solaris sp
- Closed