Name: auR10023 Date: 02/20/2003
CharsetEncoder.canEncode(char) returns true with surrogate unicode
characters in UTF-8 but javadoc for this method says:
...
This method returns false if the given character is a surrogate
character; such characters can be interpreted only when they are members
of a pair consisting of a high surrogate followed by a low surrogate
...
Here is the example:
------------- test.java --------------
import java.nio.charset.*;
public class test {
static char [] illChrs = {
'\ud800', '\ud801', '\udffe', '\udfff'
};
public static void main (String[] args) {
CharsetEncoder en = null;
try {
en = Charset.forName("UTF-8").newEncoder();
} catch(IllegalArgumentException e) {
e.printStackTrace(System.out);
System.out.println("Unexpected " + e);
return;
}
for (int j = 0; j < illChrs.length; j++) {
if (en.canEncode((char)j)) {
System.out.println("Unexpected value returned with " +
(int)illChrs[j]);
}
}
}
}
#java -version
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b16)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b16, mixed mode)
#java test
Unexpected value returned with 55296
Unexpected value returned with 55297
Unexpected value returned with 57342
Unexpected value returned with 57343
======================================================================
CharsetEncoder.canEncode(char) returns true with surrogate unicode
characters in UTF-8 but javadoc for this method says:
...
This method returns false if the given character is a surrogate
character; such characters can be interpreted only when they are members
of a pair consisting of a high surrogate followed by a low surrogate
...
Here is the example:
------------- test.java --------------
import java.nio.charset.*;
public class test {
static char [] illChrs = {
'\ud800', '\ud801', '\udffe', '\udfff'
};
public static void main (String[] args) {
CharsetEncoder en = null;
try {
en = Charset.forName("UTF-8").newEncoder();
} catch(IllegalArgumentException e) {
e.printStackTrace(System.out);
System.out.println("Unexpected " + e);
return;
}
for (int j = 0; j < illChrs.length; j++) {
if (en.canEncode((char)j)) {
System.out.println("Unexpected value returned with " +
(int)illChrs[j]);
}
}
}
}
#java -version
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b16)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b16, mixed mode)
#java test
Unexpected value returned with 55296
Unexpected value returned with 55297
Unexpected value returned with 57342
Unexpected value returned with 57343
======================================================================