The code is as follows: public static byte[] getBytesInCodePage(final String string, final int codepage) throws UnsupportedEncodingException { String encoding = codepageToEncoding(codepage); return string.getBytes(encoding); } When codepageToEncoding throws exceptions, encoding will not be set. NPOI fixed a bug: https://github.com/nissl-lab/npoi/commit/9ee6fa7de8361239dc962ccf9d5c99e65587b234 The buggy code is identical, but the fixed code handles exceptions: public static byte[] GetBytesInCodePage(String string1, int codepage) { String cp = CodepageToEncoding(codepage); Encoding encoding; try { encoding = Encoding.GetEncoding(cp); } catch (Exception) { encoding = Encoding.ASCII; } return encoding.GetBytes(string1); //return string1.GetBytes(encoding); }
I don't think we should ignore encoding issues. My gut is to not make any changes. Please provide a real world example of where we should handle invalid encodings.
As mentioned by PJ, this is likely not something that we want to change even if NPOI decided to handle it this way.