https://bz.apache.org/bugzilla/show_bug.cgi?id=68234
Bug ID: 68234 Summary: getBytesInCodePage(String,int)@CodePageUtil can fail to set encoding. Product: POI Version: 5.3.x-dev Hardware: PC Status: NEW Severity: normal Priority: P2 Component: HPSF Assignee: dev@poi.apache.org Reporter: zhong...@pku.org.cn Target Milestone: --- 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); } -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org For additional commands, e-mail: dev-h...@poi.apache.org