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

Naoto Sato naoto at openjdk.java.net
Thu Oct 21 18:04:07 UTC 2021


On Thu, 21 Oct 2021 16:06:31 GMT, Ichiroh Takiguchi <itakiguchi at openjdk.org> wrote:

> I'd like to write down following code without `try-catch`.

You don't *have to* try-catch those exceptions if you are not interested, as they are subclasses of `RuntimeException`.

> ```
> var cs = Charset.forName(charsetName, null);
> if (cs == null) cs = StandardCharsets.UTF_8;
> ```

This could be simplified to


var cs = Charset.forName(charsetName, StandardCharsets.UTF_8);

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

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


More information about the nio-dev mailing list