On Thu, 21 Oct 2021 15:00:03 GMT, Roger Riggs <rri...@openjdk.org> wrote:

>> src/java.base/share/classes/java/io/Console.java line 594:
>> 
>>> 592:                 cs = Charset.forName(StaticProperty.nativeEncoding(), 
>>> Charset.defaultCharset());
>>> 593:             } catch (Exception ignored) {
>>> 594:                 cs = Charset.defaultCharset();
>> 
>> What kind of actual improvements do we get here since the catch block is 
>> still in place?
>
> In the case of Console, both charset names come from system properties and 
> could refer to invalid or unavailable charsets.  (null is handled 
> separately).  The code silently ignores the invalid values.  The new method , 
> as is, is not a fully satisfying replacement.  Catching Exception is too 
> broad a catch but may be warranted in this case so that some Console charset 
> is selected.
> 
> The new method would be useful in more cases if the default was returned for 
> any of
> IllegalCharsetNameException, IllegalArgumentException, and 
> UnsupportedCharsetException.

Since we do support all the encodings for platforms we support out-of-the-box, 
it could still be possible that the user can specify his/her console encoding 
to the one we do not support. In that case, we can safely use the default 
`UTF-8` without throwing/catching `UnsupportedCharsetException`.

-------------

PR: https://git.openjdk.java.net/jdk/pull/6045

Reply via email to