-
Type:
Bug
-
Resolution: Fixed
-
Priority:
P4
-
Affects Version/s: 1.2.2
-
Component/s: core-libs
-
None
-
kestrel
-
generic
-
generic
In case the "malformed" character is the only character in the input buffer
or the last character in the input buffer, the return value from convertAny()
will be off-by-one. The following sample showes the problem. The expected
return value is "3" not the current "2"
import java.io.*;
import sun.io.*;
public class test_c2b {
public static void main(String args[]) {
char cc[] = new char[10];
byte bb[] = new byte[20];
CharToByteConverter c2b = null;
int i;
try {
c2b = CharToByteConverter.getConverter("ASCII");
cc[0] = (char)0xdc00;
cc[1] = (char)0xdc00;
cc[2] = (char)0xdc00;
int ret = c2b.convertAny(cc, 0, 3, bb, 0, bb.length);
System.out.println("ret=" + ret);
System.out.println("byte[0]=" + bb[0]);
System.out.println("byte[1]=" + bb[1]);
if (ret == 3);
System.out.println("byte[2]=" + bb[2]);
}
catch (Exception e){
System.out.println("c2b failed exception: " + e);
}
}
}
or the last character in the input buffer, the return value from convertAny()
will be off-by-one. The following sample showes the problem. The expected
return value is "3" not the current "2"
import java.io.*;
import sun.io.*;
public class test_c2b {
public static void main(String args[]) {
char cc[] = new char[10];
byte bb[] = new byte[20];
CharToByteConverter c2b = null;
int i;
try {
c2b = CharToByteConverter.getConverter("ASCII");
cc[0] = (char)0xdc00;
cc[1] = (char)0xdc00;
cc[2] = (char)0xdc00;
int ret = c2b.convertAny(cc, 0, 3, bb, 0, bb.length);
System.out.println("ret=" + ret);
System.out.println("byte[0]=" + bb[0]);
System.out.println("byte[1]=" + bb[1]);
if (ret == 3);
System.out.println("byte[2]=" + bb[2]);
}
catch (Exception e){
System.out.println("c2b failed exception: " + e);
}
}
}