Subject One Byte Encoders maps unknown chars to '\0' instead of '?'
Author kaneider_daniel
We have some troubles with the translation of unknown characters in
Jaybird. The encoding of our database is Win1252. If we save special
characters, they are saved as '\0' instead of the usual '?'. These
special characters include for example characters from Eastern European
countries, not included in Win1252. This '\0' value which is stored in
the database makes us technical problems, for example when we export
data in XML. UTF8 is not an option for us.

We are considering this as a bug in the
org.firebirdsql.encodings.Encoding_OneByte class, and propose to
initialize the charToByte variable with '?' chars as follows:

protected static void Initialize(String encoding, char[] byteToChar,
byte[] charToByte, char[] charMapping) {
byte[] val = new byte[1];
char[] charArray = null;
// BEGIN PATCH
Arrays.fill(charToByte, (byte)'?');
// END PATCH
for (int i=0; i< 256; i++){
val[0] = (byte) i;
try {
charArray = new String(val, 0,1,
encoding).toCharArray();
char ch = charArray[0];
byteToChar[i] = charMapping[ch];
charToByte[byteToChar[i]] = (byte) i;
}
catch (UnsupportedEncodingException uee){
uee.printStackTrace();
}
}
}