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

Sergey Bylokhov serb at openjdk.java.net
Thu Oct 21 01:35:04 UTC 2021


On Wed, 20 Oct 2021 19:02:30 GMT, Naoto Sato <naoto at openjdk.org> wrote:

>> During the review of JEP 400, a proposal to provide an overloaded method to `Charset.forName()` was suggested [[1]](https://github.com/openjdk/jdk/pull/4733#discussion_r669693954). This PR is to implement the proposal. A CSR is also drafted as https://bugs.openjdk.java.net/browse/JDK-8275348
>
> Naoto Sato has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Moved the null sentence into @param tag.

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?

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?

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

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


More information about the nio-dev mailing list