RFR: 8270490: Charset.forName() taking fallback default value [v2]

Daniel Fuchs dfuchs at openjdk.java.net
Thu Oct 21 09:37:13 UTC 2021


On Thu, 21 Oct 2021 06:50:41 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> src/java.base/share/classes/java/io/Console.java line 587:
>> 
>>> 585:                 try {
>>> 586:                     cs = Charset.forName(csname, null);
>>> 587:                 } catch (Exception ignored) { }
>> 
>> The comment which suggests this enhancement was about eliminating such "exception ignored" code paths. Is it still needed here? And if it is needed why do we pass the null as a fallback?
>
> Right, I think both try-catch usages will be removed.

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...

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

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


More information about the nio-dev mailing list