On Thu, 21 Oct 2021 16:03:29 GMT, Naoto Sato <na...@openjdk.org> wrote:
>> Apparently `IllegalCharsetNameException` or `IllegalArgumentException` could >> still be thrown - so removing the `try-catch` would be a change of behaviour >> in those cases. It all depends on whether there is a chance that these >> exceptions could be thrown in this particular context (with these particular >> input parameters) - which I am not able to tell - but maybe someone more >> familiar with this code could... > > I first thought of swallowing all exceptions in 2-arg forName(), but decided > not to do that. Because `IllegalArgumentException` and > `IllegalCharsetNameException` are for the validity of the passed > `charsetName`, like detecting `null` or invalid chars like "😱". On the other > hand, `UnsupportedCharsetException` is for the availability which varies > depending on the user's settings and or platform, which can be safely > replaced with `fallback` charset. So yes, it is not totally getting rid of > `try-catch` but it avoids `UnsupportedCharsetException` which is only > detectable at runtime. Then what is the benefit, if the user will have to write such code anyway?: try { cs = Charset.forName(StaticProperty.nativeEncoding(), fallback); } catch (Exception ignored) { cs = fallback; } Even in the current code update it can work well w/o the second parameter. ------------- PR: https://git.openjdk.java.net/jdk/pull/6045